Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Sorting an array of lines

by indapa (Monk)
on Feb 08, 2002 at 21:55 UTC ( #144258=note: print w/replies, xml ) Need Help??

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:~$

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://144258]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2019-12-05 15:06 GMT
Find Nodes?
    Voting Booth?
    Strict and warnings: which comes first?

    Results (151 votes). Check out past polls.