neversaint has asked for the wisdom of the Perl Monks concerning the following question:
my %bighash = ( 'set1' => { 'STORE1' => [10,['1','BOOK'],['2','PENCIL']], 'STORE2' => [8,['0','CHALK'],['4','PEN']], }, 'set2' => { 'STORE3' => [13,['1','BOOK'],['2','PENCIL']], 'STORE4' => [11,['0','CHALK'],['4','PEN']], }, 'set3' => { 'STORE5' => [2, ['1','BOOK'],['2','PENCIL']], 'STORE6' => [70,['0','CHALK'],['4','PEN']], }, 'set4' => { 'STORE7' => [19,['1','BOOK'],['2','PENCIL']], 'STORE8' => [20,['0','CHALK'],['4','PEN']], } ); # list of selected stores (st) my @st = ('STORE2','STORE3','STORE5'); foreach ( @st ) { foreach my $grp ( sort {$bighash{$b}{$_}[0] <=> $bighash{$a}{$_}[0]} keys %bighash ) { if ( defined $bighash{$grp}{$_}) { print "STORE: $_ EARNING:$bighash{$grp}{$_}[0]\n"; foreach my $j ( 1 .. (@{$bighash{$grp}{$_}})-1 ) { print join(",",@{$bighash{$grp}{$_}[$j]}),"\n"; } print "\n"; } } }
What's wrong with my "sorting syntax" above?STORE: STORE3 EARNING:13 1,BOOK 2,PENCIL STORE: STORE2 EARNING:8 0,CHALK 4,PEN STORE: STORE5 EARNING:2 1,BOOK 2,PENCIL
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sorting by Hash Slice
by tlm (Prior) on Jul 28, 2005 at 04:16 UTC | |
|
Re: Sorting by Hash Slice
by sacked (Hermit) on Jul 28, 2005 at 04:57 UTC |