in reply to HoH problem

Here's my go!

I've just flattened it into an array and sorted it.

my @flat_data; for my $file (keys %hoh){ for my $letter (keys %{$hoh{$file}}){ my $weight = $hoh{$file}{$letter}{weight}; my $intensity = $hoh{$file}{$letter}{intensity}; push @flat_data, "weight: $weight intensity $intensity Filename: $file"; } } print "$_\n" for sort @flat_data;
output:
---------- Capture Output ---------- > "c:\perl\bin\perl.exe" _new.pl weight: 1000 intensity 4 Filename: FILENAME3 weight: 2000 intensity 7 Filename: FILENAME2 weight: 3000 intensity 2 Filename: FILENAME1 weight: 4000 intensity 3 Filename: FILENAME1 weight: 5000 intensity 3 Filename: FILENAME2 weight: 6000 intensity 3 Filename: FILENAME3 > Terminated with exit code 0.

Replies are listed 'Best First'.
Re^2: HoH problem
by ikegami (Patriarch) on Nov 07, 2006 at 15:31 UTC
    That won't work if one weight is 120 and another is 1000. Fix:
    my @flat_data; for my $file (keys %hoh){ for my $letter (keys %{$hoh{$file}}){ my $weight = $hoh{$file}{$letter}{weight}; my $intensity = $hoh{$file}{$letter}{intensity}; push @flat_data, [ $weight, $intensity, $file ]; } } printf "weight: %d intensity %d Filename: %s\n", @$_ for sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] || $a->[2] cmp $b->[2] } @flat_data;