deprecated has asked for the wisdom of the Perl Monks concerning the following question:
I want every key from HoH where $HoH -> {foo} eq 'bar2'. Seems to me that sort would work. Im actually pretty curious what it thinks im asking it to do. Can anyone shed some light on this?my %HoH = ( 1 => +{ foo => 'bar', baz => 'bletch', }, 2 => +{ foo => 'bar2', baz => 'bletch2', }, ); my @fookeys; # select 'foo' from 'HoH' where 'foo' = 'bar2' @fookeys = sort { $HoH{$a} -> {foo} eq 'bar2' } keys %HoH; use Data::Dumper; # fookeys is [ 1, 2 ] print Dumper \@fookeys; # try again @fookeys = sort { $HoH{$a}{foo} eq 'bar2' } keys %HoH; # fookeys is [ 1, 2 ] print Dumper \@fookeys;
Thanks,
brother dep.
--
Laziness, Impatience, Hubris, and Generosity.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(ar0n) Re: Using 'sort' to emulate SQL's 'select'...
by ar0n (Priest) on Apr 22, 2001 at 19:41 UTC | |
by deprecated (Priest) on Apr 22, 2001 at 19:51 UTC | |
|
Re: Using 'sort' to emulate SQL's 'select'...
by lucs (Sexton) on Apr 22, 2001 at 21:35 UTC |