in reply to Mind Bending Arrays

@array = sort {$b->[1] <=> $a->[1] } ( ['adsf.htm',10], ['sdfg.htm',7], ['qwet.htm',4], ['zxcv.htm',2], );

Replies are listed 'Best First'.
Re: Re: Mind Bending Arrays
by cronus (Initiate) on Jan 04, 2001 at 19:14 UTC
    I appreciate the help, but bare in mind I have no experience with arrays at all. From reading through other posts on arrays, I know I can do;
    @array = sort ($b->[1] <=> $a->[1]) @array;
    but how do I fill the array with the filename and number in the first place ?
      You should probably be using a hash instead.

      my %hash; while (my ($filename, $number) = &get_both) { $hash{$filename} = $number; } my @sorted_files = sort { $hash{$a} <=> $hash{$b} } keys %hash;
      If you really need to put this in an array (to keep track of the insertion order, for example), you could probably do it like this:
      my @array; while (my ($filename, $number) = &get_both) { push(@array, [ $filename, $number ]); } my @sorted = sort { $a->[1] <=> $b->[1] } @array;