in reply to Pushing arrays into hashes
my $party = (grep $_->[0] eq 'fish', @$pairs)[0]->[1];
though it's more a case of just being different ways to do it, rather than better ways.use List::Util 'first'; my $party = (first {$_->[0] eq 'fish'} @$pairs)->[1];
What probably would be better is to make a function "as_hash" that would do the conversion to a hashref (the map), so that your code would be more self-documenting.
sub as_hash { my $aref = shift; return { map @$_, @$aref }; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Pushing arrays into hashes
by BiffBaker (Novice) on Jun 22, 2007 at 23:42 UTC |