Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Minnesotan Translator

by Frey (Novice)
on May 17, 2001 at 01:50 UTC ( [id://81100]=CUFP: print w/replies, xml ) Need Help??

I hate it when people don't understand my native tongue. Now they can be helped. I just put a bunch of animals from the oakland zoo in my animals.txt file, it saved typing time. So choose your favorite animals and put them in that file, one per line, and everything should work great. Oh, and do me a favor and inclue Jesse Ventura on your animal list.
print "Type in a sentence, and I'll translate it dontcha know. Type quit when you're done, if you feel like it that is.\n"; while($a=<> and $a ne "quit\n"){ chomp $a; open(ANIMALS,"animals.txt"); while(chomp ($b=<ANIMALS>)){ $a =~ s/$b/cow/i;} @b=split(/(\s)/i,$a); foreach(@b){s/yes|sure|okay/you bet/i; s/\./ dontcha know./i; } print @b; close ANIMALS; }

Replies are listed 'Best First'.
Re: Minnesotan Translator
by premchai21 (Curate) on May 17, 2001 at 07:03 UTC
    I'm sorry, but I couldn't resist improving (?) on this...
    #!/usr/bin/perl -w use strict; use Getopt::Long; my ($animalfile, $animal_regex) = ('animals.txt',''); GetOptions('animalfile=s' => \$animalfile); (-f $animalfile) or die "Whoops! File \"$animalfile\" doesn't exist.\ +n"; print "Using animal file: $animalfile\n"; open ANIMALS, $animalfile; $animal_regex = "\\b(?:" . (join '|', grep { $_ } map { chomp; quoteme +ta; } <ANIMALS>) . ")s?\\b"; close ANIMALS; print <<PRINT; Type in a sentence, and I'll translate it dontcha know. Type quit when you're done, if you feel like it that is. PRINT while (chomp ($_ = <STDIN>)) { last if ($_ eq 'quit'); s/$animal_regex/cow/iog; s/\b(?:yes|sure|okay)\b/you bet/ig; s/\.$/ dontcha know./; print "$_\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://81100]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-26 04:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found