Rick wrote:
John W. Krahn wrote:
Rick wrote:
should this not work?

Based upon the code presented, it looks like the code it correct.

I am finding out that Length is *NOT* being sorted correctly numerically...

Of course we don't know the data stored in %in_array and %in_array_c so it is hard to say why it is not working the way you want it.

for my $d ( sort { $in_array{$b} <=> $in_array{$a} }  keys %in_array ){
      printf "SERVER:%-20s %-20s\n",$d,$in_array{$d};

      for my $key30 (  keys %{ $in_array_c{$d} }  ) {
         for my $key20 (  keys %{ $in_array_c{$d}{$key30} }  ) {
for my $key ( sort { $in_array_c{$d}{$key30}{$key20}{$b} <=> $in_array_c{$d}{$key30}{$key20}{$a} } keys %{ $in_array_c{$d}{$key30}{$key20} } ) {
                my $str = substr( ( (split(/_/,$key))[2]),0,12);
print "\tLENGTH: $in_array_c{$d}{$key30}{$key20}{$key} \n";
            }
         }
      }
}

let's say you have a hash reference as below

$has_ref{$a}{$b}{$c}{$d} where a-c represents somethign simple say $a = 'car' $b = 'plane' $c = 'sports' and $d = 'year' and I wanted to sort by value of year. I thought above lines will work but it's not being sorted out correctly and I thought I made some obvious mistakes or perhaps there was better ways to do this.

Like I said, based on the limited amount of code and data presented there is no way to debug your code from here.

Perhaps you should use something like Data::Dumper to print out the %in_array_c hash to see if the 'year' values are actually numeric values.

Also, are you using the warnings and strict pragmas to let perl help you find mistakes in the code?


John
--
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to