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:

  1. Setting the input record separator $/ and the output record separator $\ to a newline "\n" (the -l switch), in this case this is mainly useful for not having to add a newline when printing output
  2. Reading the input line-by-line in a while loop (the -n switch), and for each line:
    1. Removing the input record separator (newline) with chomp (the -l switch)
    2. splitting the line on the character : into the array @F (the -aF: switches)
    3. pushing the first element of the array, $F[0], onto the array @x, if the input line $_ matches /^[A-Z]/ (the code from the -e switch)
  3. After that loop,
  4. Loop over the sorted elements of @x, printing each one. (also the -e switch, after the }{)

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.


In reply to Re^3: Parse a text file with oneliner (updated) by haukex
in thread Parse a text file with oneliner by RenMcCourtey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.