in reply to Sorting an array of lines

Take a look at Complex Sorting, it's an excellent explaination of what you need.
#!/apps/bin/perl -w my (@array, @sorted) =(); while (<>) { chomp; push (@array, $_); } @sorted = map {$_->[0]} sort {$a->[1] <=> $b->[1]} map { my ($sortvalue) = /(\d+)$/; [$_,$sortvalue]; } @array; print "@sorted\n";

Replies are listed 'Best First'.
Re: Re: Sorting an array of lines
by Juerd (Abbot) on Feb 08, 2002 at 22:42 UTC
    print "@sorted\n";
    Probably not what you want. You chomped the initial list, and $" is usually not set to \n.

    Either don't chomp (don't chomp unless you need the data chomped) and print @sorted; or print "$_\n" for @sorted; or print map "$_\n", @sorted;.

    2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$