Current location: Hot Scripts Forums » Programming Languages » Windows .NET Programming » Perl > C# Transformation?


Perl > C# Transformation?

Reply
  #1 (permalink)  
Old 09-09-06, 05:24 PM
CADD CADD is offline
New Member
 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Perl > C# Transformation?

Can anyone help transform this Perl into C#?


use LWP::UserAgent;
Code:
# 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 help.

Last edited by nico_swd; 09-09-06 at 05:28 PM.
Reply With Quote
  #2 (permalink)  
Old 09-09-06, 05:38 PM
curbview.com's Avatar
curbview.com curbview.com is offline
Junior Code Guru
 
Join Date: May 2006
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
This should be moved to a different section.
Reply With Quote
  #3 (permalink)  
Old 09-09-06, 05:46 PM
CADD CADD is offline
New Member
 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
why?

this is the perl forum, isn't it?
Reply With Quote
  #4 (permalink)  
Old 09-09-06, 07:27 PM
Christian's Avatar
Christian Christian is offline
Community VIP
 
Join Date: Mar 2005
Location: ProgrammingTalk
Posts: 2,449
Thanks: 0
Thanked 6 Times in 5 Posts
Quote:
Originally Posted by curbview.com
This should be moved to a different section.
Indeed!

Moved to C#.
__________________
:: ImperialBB :: New version in the works! :: http://www.imperialbb.com ::

:: Have a question about the board? The Rules? An Infraction/Warning? :: Contact Form ::
Reply With Quote
  #5 (permalink)  
Old 09-09-06, 07:29 PM
Christian's Avatar
Christian Christian is offline
Community VIP
 
Join Date: Mar 2005
Location: ProgrammingTalk
Posts: 2,449
Thanks: 0
Thanked 6 Times in 5 Posts
Quote:
Originally Posted by CADD
why?

this is the perl forum, isn't it?
Yes, it was the Perl forum, but your target language is not Perl it's C#. Thus it should be in the C# forum.
__________________
:: ImperialBB :: New version in the works! :: http://www.imperialbb.com ::

:: Have a question about the board? The Rules? An Infraction/Warning? :: Contact Form ::
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl for a dummy kragnesb414 Perl 1 01-31-06 04:34 AM
Execute a perl script from another perl script. jkarimi Perl 3 09-06-05 11:42 PM
Avoid chaging the path to perl (shebang) on every upload to server uniqueuser Perl 2 04-19-05 02:27 PM
Perl FormMail Problem ennanguyen2002 Perl 2 03-09-05 04:47 PM
Perl coder needed XGamingZone Perl 1 09-17-04 07:19 AM


All times are GMT -5. The time now is 02:16 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.