Perl > C# Transformation?

C

CADD

Can anyone help transform this Perl into C#?

use LWP::UserAgent;

# Our user ID.

my $custid = "Test";

# Our message.

my $msg = "Hello";

# Lowercase and remove spaces/underscores in user name.

$custid = lc($custid);
$custid =~ s/ //ig;
$custid =~ s/_//ig;

# Create a new useragent. This creates an instance of the UserAgent
module.
# Name your agent whatever you like or keep the default. Your bot's
name is
# a good suggestion.

$ua = new LWP::UserAgent;
$ua->agent("AgentName/1.0 " . $ua->agent);

# Create a request. This sets up the POST string.
# Field values sent two diff ways shown here. You will need to add your
own
# bot's id for the botid= field.

my $req = new HTTP::Request POST
=>("http://www.pandorabots.com/pandora/talk-xml?botid=id
here&input=$msg");
$req->content_type('application/x-www-form-urlencoded');
$req->content("custid=$custid");

# Pass request to the user agent and get a response back.

my $res = $ua->request($req);

# Create a variable to hold content. You now have the
# full source of the reply from the API, including markup, user input,
# and Pandora response code.

my $reply = $res->content;

# Create a variable holding everything in between <that></that> tags,
which
# is where the actual bot reply is.

($response = $reply) =~ s/^.*(\<that\> .*)\<\/that\>.*$/$1/m;

# Strip remaining tags and trim string.

$response =~ s/<that>/ /g;
$response =~ s/^\s+//;
$response =~ s/\s+$//;

# Convert tags for quotes and links in AIML.

$response =~ s/&quot;/\"/g;
$response =~ s/&amp;lt;/</g;
$response =~ s/&amp;quot;/\"/g;
$response =~ s/&amp;gt;/>/g;

# $response now holds just the bot's reply. Print or return $response
here
based on your app.


Thank you in advance for your time.
 
P

Paul Lalli

CADD said:
Can anyone help transform this Perl into C#?

What exactly do you need help with? Do you not understand some part of
the Perl code? If so, ask specific questions about the part(s) you
don't understand. Do you not know the syntax for C#? If so, ask a
group that deals with C#. This is not such a group.

Paul Lalli
 
C

CADD

Paul said:
What exactly do you need help with? Do you not understand some part of
the Perl code? If so, ask specific questions about the part(s) you
don't understand. Do you not know the syntax for C#? If so, ask a
group that deals with C#. This is not such a group.

Paul Lalli

Thank you for the reply.

I would like the transform the above Perl code to C# - does such
transformation package exist?
 
T

Tad McClellan

CADD said:
I would like the transform the above Perl code to C# - does such
transformation package exist?


There is no way to do that automatically.

You will need a programmer that understands both languages to
translate it for you (or learn both languages yourself).
 
M

Matt Garrish

CADD said:
I would like the transform the above Perl code to C# - does such
transformation package exist?

No, and this isn't a C# group, so you're kind of going at things
backward. If you don't know regular expressions in C# take a look at
the following:

http://www.windowsdevcenter.com/pub/a/oreilly/windows/news/csharp_0101.html

As for the LWP stuff, you might take a look at the WebRequest and
HttpRequest classes in System.Web. It's not going to be as nice and
easy as using LWP, but if you google on those classes and posting files
I'm sure you'll find what you need in time.

Matt
 
B

Brian McCauley

Tad said:
There is no way to do that automatically.

You will need a programmer that understands both languages to
translate it for you (or learn both languages yourself)

Well actually the varoius Perl6 projects promise ways to compile Perl6
to run on various backends which could in prinicple include C#. And of
course there's a Perl5 to Perl6 translator. So in a few years time
there could indeed be tools to do it automatically. Of course it would
not produce efficient or ideomatic C#.
 
C

CADD

Brian said:
Well actually the varoius Perl6 projects promise ways to compile Perl6
to run on various backends which could in prinicple include C#. And of
course there's a Perl5 to Perl6 translator. So in a few years time
there could indeed be tools to do it automatically. Of course it would
not produce efficient or ideomatic C#.

Looks like I'll be stuck for a few years. I've been banging my head
against the wall trying to figure out these two codes and they aren't
really within the scope of my project.

I have heard others asking for it as well.

Sounds like something useful to sell.

Thanks for the reply.
 
C

CADD

Tad said:
There is no way to do that automatically.

You will need a programmer that understands both languages to
translate it for you (or learn both languages yourself).

It sounded like that was the case.

Learning these two on top of the main scope of what I'm working in has
not made this a fun weekend.

Thanks for the reply.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,187
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top