What would really help me is if you would rewrite
echo -e "abc\ndef\nghi\n" | perl -wlne '! /def/ and print "$_";'
for me with "-we" in place of "-wple" with all the short hand and defaults removed so I could see exactly what is going on.

Perl does that for you, at least the part after the pipe char, if you load B::Deparse (comments mine):

qwurx [shmem] ~> perl -MO=Deparse,-x -wlne '! /def/ and print "$_";' BEGIN { $^W = 1; } # this is -w BEGIN { $/ = "\n"; $\ = "\n"; } # this is -l LINE: while (defined($_ = <ARGV>)) { # and here is what -n does... chomp $_; # this belongs to -l print "$_" unless /def/; } # this belongs to -n too -e syntax OK

The only line without comment is -e, i.e. your command line script body.

Here's another example - count lines, invented by Abigail:

perl -ne '}{ print $.'

The }{ construct - named eskimo greeting - splits the implicit while loop into a while loop block and a bare block:

perl -MO=Deparse,-x -ne '}{print$.' LINE: while (defined($_ = <ARGV>)) { # -n (); # script body - a noop } # script body { # script body print $.; # script body } # -n

The bare block is used to output the current line number of the (special) filehandle ARGV.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

In reply to Re^5: Regex match on implicit default variable ($_) in a script, not a one liner by shmem
in thread Regex match on implicit default variable ($_) in a script, not a one liner by Todd Chester

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.