martin_100 has asked for the wisdom of the Perl Monks concerning the following question:
The following code was an answer posted to a query a long time back on how to sort a text file that had 5 columns of numbers and the user wanted to sort based on 2nd column. I don't understand the solution and was hoping someone could explain it.
use strict; use File::Slurp qw(read_file); print map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [(split /\s+/)[1], $_] } read_file( $ARGV[0] );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how does these map statements work
by frozenwithjoy (Priest) on Aug 06, 2014 at 08:56 UTC | |
|
Re: how does these map statements work
by AppleFritter (Vicar) on Aug 06, 2014 at 09:40 UTC | |
|
Re: how does these map statements work
by AnomalousMonk (Archbishop) on Aug 06, 2014 at 10:25 UTC | |
|
Re: how does these map statements work
by Anonymous Monk on Aug 06, 2014 at 08:36 UTC |