in reply to Minnesotan Translator
#!/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"; }
|
|---|