in reply to Re^2: Parse a text file with oneliner
in thread Parse a text file with oneliner
The switches -lanF: basically add some code to the oneliner provided with -e, this is described in perlrun, but you can also use B::Deparse to turn the oneliner into a script to see it:
$ perl -MO=Deparse -F: -lane 'push @x, $F[0] if /^[A-Z]/}{print for so +rt @x' BEGIN { $/ = "\n"; $\ = "\n"; } LINE: while (defined($_ = readline ARGV)) { chomp $_; our @F = split(/:/, $_, 0); push @x, $F[0] if /^[A-Z]/; } { print $_ foreach (sort @x); }
Which shows you that the script is:
Cleaning up the above code gives you this script:
use warnings; use strict; my @out; while (<>) { chomp; my @fields = split /:/; push @out, $fields[0] if /^[A-Z]/; } print "$_\n" for sort @out;
Update: Added references to the corresponding switches to the above list and expanded explanation of -l.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Parse a text file with oneliner (updated)
by RenMcCourtey (Acolyte) on Aug 28, 2017 at 12:07 UTC |