in reply to grep keys in hash and retrieve values
I think my $matching_key, is returning the number of keys that match the grep and not the actual hash key.
Then you should write a program to check
$ perl -le " print scalar grep /./, qw/ a b c /; " 3
Yup, grep in scalar context returns the number of matches.
Now in list context it returns a list :)
$ perl -le " print for grep /./, qw/ a b c /; " a b c
So to get the first from the list, we use parens
$ perl -le " ( $foo ) = grep /./, qw/ a b c /; print $foo " a $ perl -le " print( ( grep /./, qw/ a b c / )[0] ); " a
See Tutorials: Context in Perl: Context tutorial
And see again Re: help with loop and start making functions, your program is very hard to read :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: grep keys in hash and retrieve values
by AWallBuilder (Beadle) on Mar 16, 2012 at 10:40 UTC |