in reply to Sort textfile

Sort returns the array sorted, it does not sort it in place. So just move your sort into the foreach

foreach my $line(sort @resultArray){

Now it uses the sorted array returned from the sort. Alternately you could modify your sort line to save that back into the orignal array.

@resultArray = sort { $a<=>$b } @resultArray;

Could anyone comment as to why sort doesn't do an inplace sort when called in void context?


___________
Eric Hodges

Replies are listed 'Best First'.
Re: Re: Sort textfile
by chromatic (Archbishop) on Apr 13, 2004 at 21:18 UTC

    What do you expect this would do?

    sort { $a cmp $b } qw( one two three );

    That's not intractable, but it's one of a few questions to ponder for this feature.