What would really help me is if you would rewritefor me with "-we" in place of "-wple" with all the short hand and defaults removed so I could see exactly what is going on.echo -e "abc\ndef\nghi\n" | perl -wlne '! /def/ and print "$_";'
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.
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |