I have a hash I am trying to sort. However, I am trying to sort it by deeper values than has been discussed on the monastery before. (I spent a good hour in the Super Search). So here's some test code:
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;
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?
Thanks,
brother dep.
--
Laziness, Impatience, Hubris, and Generosity.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.