bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monasterians,
First, apologies for that convoluted title.
Here's the scenario:
So:
my $AoH = [ { name => "Bob", gender => "M" }, { name => "Sue", gender => "F" }, { name => "Mike", gender => "M" } ];
And then magically:
Loop code I would normally use:my $template->param( men => all pairs where $AoH{gender] eq "M", women => all pairs where $AoH{gender] eq "F" );
my ($men, $women); my $m = 0; my $w = 0; for my $i ( 0 .. $#$AoH ) { if ($AoH->[$i]{gender} eq "M") { $men->[$m] = $AoH->[$i]; $m++; } else { $women->[$w] = $AoH->[$i]; $w++; } } my $template->param( men => $men, women => $women );
Just looking for a cleaner way to do this. Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Assigning AoH pairs by value other AoH's
by Tanktalus (Canon) on Sep 10, 2005 at 17:55 UTC | |
by bradcathey (Prior) on Sep 10, 2005 at 18:25 UTC | |
|
Re: Assigning AoH pairs by value other AoH's
by pg (Canon) on Sep 10, 2005 at 17:50 UTC | |
|
Re: Assigning AoH pairs by value other AoH's
by nedals (Deacon) on Sep 10, 2005 at 22:25 UTC |