Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl # Wasteful to use use strict; use warnings; my %known = ("foo" => "FOO", "bar" => "BAR", "baz" => "BAZ"); print "Talk to me, Goose."; my $input = <STDIN>; chomp($input); foreach my $maybe (keys %known) { if ($input =~ /$maybe/i ) { print "You gave us $input, which equates to $known{$input}. Go +od night, and good luck.\n"; last; } else { print "Not a match. YET!\n"; } } #!/usr/bin/perl #picky about its inputs use strict; use warnings; my %known = ("foo" => "FOO", "bar" => "BAR", "baz" => "BAZ"); print "Talk to me, Goose."; my $input = <STDIN>; chomp($input); print "You gave us $input, which equates to $known{$input}. Have a nic +e day.\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Checking input against known
by BrowserUk (Patriarch) on Aug 02, 2006 at 03:54 UTC | |
|
Re: Checking input against known
by duckyd (Hermit) on Aug 02, 2006 at 03:59 UTC | |
|
Re: Checking input against known
by GhodMode (Pilgrim) on Aug 02, 2006 at 04:03 UTC | |
|
Re: Checking input against known
by McDarren (Abbot) on Aug 02, 2006 at 04:02 UTC | |
|
Re: Checking input against known
by Samy_rio (Vicar) on Aug 02, 2006 at 04:08 UTC | |
by McDarren (Abbot) on Aug 02, 2006 at 04:16 UTC | |
|
Re: Checking input against known
by Mandrake (Chaplain) on Aug 02, 2006 at 05:43 UTC |