in reply to Search a hash for STDIN and report findings
foreach ($input)
There's no need for a foreach loop over one element, so leave that out.
I rewrote your example in a way that I think you intended:
use strict; use warnings; my %passwords = ( moritz => 'secret', ); while(<STDIN>) { chomp; if (exists $passwords{$_}){ print "Password from $_ is '$passwords{$_}'\n"; } else { print "No password for $_, sorry\n"; } }
And this is how a run could look like:
$ perl script.pl moritz Password from moritz is 'secret' someone else No password for someone else, sorry
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Search a hash for STDIN and report findings
by trenchwar (Beadle) on Feb 07, 2008 at 18:51 UTC | |
by moritz (Cardinal) on Feb 07, 2008 at 19:37 UTC | |
by toolic (Bishop) on Feb 07, 2008 at 19:46 UTC | |
by moritz (Cardinal) on Feb 07, 2008 at 21:08 UTC | |
by trenchwar (Beadle) on Feb 07, 2008 at 21:35 UTC | |
by trenchwar (Beadle) on Feb 07, 2008 at 21:09 UTC |