open my $fh, '<', $file; my @ary = <$fh>; print # print the list consisting of map { $_->[1] } # all second elements sort { $a->[0] <=> $b->[0] } # of a sorted list of anon arrays map { # constructed via my ($d) = />(\d+)/; # extracting the numbers to be sorted [ $d, $_ ] # as an anon array of number and line } @ary; # for all lines of the file
See A brief tutorial on Perl's native sorting facilities..
See also: open, print, map, sort. For anonymous arrays see References quick reference, the perldata, perlref and perlreftut manual pages.
In reply to Re: Sorting help
by shmem
in thread Sorting help
by raj123
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |