in reply to Sort textfile

You are using sort incorrectly.

sort returns the sorted array, it does not sort the array.

See example below:

perl -e '@a=(1,5,3);@b=sort @a; print "@a\n"; print "@b\n";'
with output
1 5 3 1 3 5

Replies are listed 'Best First'.
Re: Re: Sort textfile
by Anonymous Monk on Apr 13, 2004 at 22:02 UTC
    Guys, It's not sorting
      You have two problems in your code.

      (1) sort @array
      does not sort the array, it returns the sorted array

      (2) sort {$a <=> $b} @array
      sorts numbers, not strings.

      To fix this, use default sorting of sort (or explicitly compare strings) and assign it to a new array.

      @sorted = sort @array;
      or
      @sorted = sort {$a cmp $b} @array;

      Sandy