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"; }