I have the following code:
my @AoH = (
{
Lead => "fred",
Wife => "wilma",
Son => "bambam",
},
{
Lead => "george",
Wife => "jane",
Son => "elroy",
},
{
Lead => "homer",
Wife => "marge",
Son => "bart",
});
for my $i ( 0 .. $#AoH )
{
print "$i is { ";
for my $role ( keys %{ $AoH[$i] } )
{
print "$role=$AoH[$i]{$role} ";
}
print "}\n";
}
This gives the following output:
0 is { Son=bambam Lead=fred Wife=wilma}
1 is { Son=elroy Lead=george Wife=jane }
2 is { Son=bart Lead=homer Wife=marge }
I want to create another array of hashes that sorts the original array of hashes based on the values of the "Son" field, so the output becomes:
Original AoH:
0 is { Son=bambam Lead=fred Wife=wilma}
1 is { Son=elroy Lead=george Wife=jane }
2 is { Son=bart Lead=homer Wife=marge }
New AoH:
0 is { Son=bambam Lead=fred Wife=wilma}
1 is { Son=bart Lead=homer Wife=marge }
2 is { Son=elroy Lead=george Wife=jane }
How do I do this?
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.