in reply to Re: Sort textfile
in thread Sort textfile

Guys, It's not sorting

Replies are listed 'Best First'.
Re: Re: Re: Sort textfile
by Sandy (Curate) on Apr 14, 2004 at 15:08 UTC
    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