in reply to Re: Mind Bending Arrays
in thread Mind Bending Arrays

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 ?

Replies are listed 'Best First'.
Re: Re: Re: Mind Bending Arrays
by Fastolfe (Vicar) on Jan 05, 2001 at 01:10 UTC
    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;