bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monasterians,
I have no problem sorting an AoH, but when I try to sort it as a reference (as I fetchall_arrayref it from MySQL for a HTML::Template loop) I get zero results. I've Googled and SS'ed with little success. Anyway, what am I missing? Thanks.
my $sqldata = [ { level => 2, menuname => 'cccccc' }, { level => 3, menuname => '333333' }, { level => 3, menuname => '222222' }, { level => 1, menuname => 'CCCCCC' }, { level => 2, menuname => 'bbbbbb' }, { level => 1, menuname => 'BBBBBB' }, { level => 1, menuname => 'AAAAAA' }, { level => 3, menuname => '111111' }, { level => 2, menuname => 'aaaaaa' }, ]; my $sorted = sort { $a->{level} <=> $b->{level} || [$a->{menuname} cmp $b->{menuname} } @$sqldata; for ( 0 .. $#$sorted ) { print $sorted->[$_]{level}." ".$sorted->[$_]{menuname}."<br>"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to sort a AoH reference
by dragonchild (Archbishop) on Jun 01, 2005 at 14:38 UTC | |
|
Re: How to sort a AoH reference
by Transient (Hermit) on Jun 01, 2005 at 14:41 UTC | |
|
Re: How to sort a AoH reference
by tlm (Prior) on Jun 01, 2005 at 16:34 UTC | |
|
Re: How to sort a AoH reference
by prasadbabu (Prior) on Jun 01, 2005 at 14:39 UTC | |
|
Re: How to sort a AoH reference
by mda2 (Hermit) on Jun 01, 2005 at 17:07 UTC | |
|
Re: How to sort a AoH reference
by TedPride (Priest) on Jun 01, 2005 at 18:19 UTC |