in reply to Assist in understanding old code

#@indexUlt=sort{$nxxult[$a]<=>$nxxult[$b]} 0 ... $#nxxult;

I would have said that one of the values in the array that's being sorted is undefined, except the whole line appears to be commented out. What's really going on with this code, do you know?

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Replies are listed 'Best First'.
Re^2: Assist in understanding of old code
by ozgurp (Beadle) on Feb 28, 2005 at 23:18 UTC
    Sorry it should not have been commented out, so the code is:
    my $ct=0; my @nxxult = (); my @Ultmnsort = (); my @indexUlt = (); for(my $rn=4;$rn<=32;$rn +=4) { for(my $bn=1;$bn<=$row[0];$bn++) { $nxxult[$bn]=$ldx[$bn][$rn]; } @indexUlt=sort{$nxxult[$a]<=>$nxxult[$b]} 0 ... $#nxxult; $Ultmnsort[$ct]=$indexUlt[0]; $Ultmxsort[$ct]=$indexUlt[$#indexUlt]; $ct++; }
    I don't really know what is going on in this code, I am working on it.

      Well then, if the line shouldn't actually be commented out, then the problem is as talexb described, "one of the values in the array that's being sorted is undefined." You have two ways of solving that problem:

      • Use an empty string value instead of undef
      • Turn off the warning

      Which solution you pick will usually depend highly on the application. I tend to structure my apps in a way that an empty string makes more sense than undef, but perhaps this one isn't. In that case, turning off the warning (using a lexically scoped no warnings) would be the best option.