monkfan has asked for the wisdom of the Perl Monks concerning the following question:
Would like to print *only* the top sorted Hash based on the zeroeth element of the value.my $HoA_ref = {'GAT' => [2, ['ttt',-3,1],['ttc',-3,3],['ccc',-1,2]], 'AAA' => [13,['aaa',-1,2],['atg',-2,2]], 'TTT' => [11,['tta',-2,1],['atc',-3,3]] }; # Need to print 'AAA' slice only coz have'13' as highest value
I tried this function but of no avail:AAA 13: aaa,-1,2 atg,-2,2
How can I go about it?#namely how can I pick only the topmost with this subroutine #besides some reference error that I encounter. sub print_zHoA { my ($HoA) = @_; foreach my $mc (sort {$HoA{$a}[0] <=> $HoA{$b}[0]} keys %$HoA){ print "$mc $HoA{$mc}[0]:\n"; foreach my $i (0.. $#{$$HoA{$mc}}) { print "$$HoA{$mc}[$i]->[0],$$HoA{$mc}[$i]->[1],$$HoA{$mc}[$i]- +>[2]"; } print "\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Printing a Hash Slices problem
by friedo (Prior) on Feb 28, 2005 at 16:57 UTC | |
by Roy Johnson (Monsignor) on Feb 28, 2005 at 18:59 UTC | |
|
Re: Printing a Hash Slice problem
by dorward (Curate) on Feb 28, 2005 at 17:21 UTC | |
by dorward (Curate) on Feb 28, 2005 at 17:32 UTC | |
|
Re: Printing a Hash Slice problem
by deibyz (Hermit) on Feb 28, 2005 at 17:32 UTC | |
|
Re: Printing a Hash Slice problem
by Taulmarill (Deacon) on Feb 28, 2005 at 18:09 UTC | |
by monkfan (Curate) on Mar 02, 2005 at 07:28 UTC | |
by jhourcle (Prior) on Mar 03, 2005 at 01:18 UTC | |
|
Re: Printing a Hash Slice problem
by osunderdog (Deacon) on Feb 28, 2005 at 17:34 UTC |