[tpm] Skip lines when "perl -wn"

Tom Legrady legrady at gmail.com
Thu Apr 2 15:25:51 PDT 2015


I have good results using $., the line number of the file being read.

perl -ne' next if $. <= 2; printf "%3d - %s". $., $_; ' Build.PL

perl -MEnglish -ne 'next if $NR <= 2; printf "%3d - %s". $., $_; ' Build.PL

perl -MEnglish -ne 'next if $INPUT_LINE_NUMBER <= 2; printf "%3d - %s". 
$., $_; ' Build.PL


skips lines 1 & 2, and outputs the remainder.

Tom


On 04/02/2015 11:00 AM, Antonio Sun wrote:
> The "-n" causes Perl to assume a loop around the program, which makes 
> it iterate over filename arguments somewhat like `sed -n` or awk.
>
> Now, is it possible to skip some lines myself in such "perl -wn" script?
>
>     #!/usr/bin/perl -wn
>
>     if (/my case/) {
>       # Skip two lines
>       <>; <>;
>       # Deal with the rest
>     }
>
>
> The above is not working for me. $_ is stuck at the same line/content.
>
> How to skip some lines in such "perl -wn" script?
>
> Thanks
>
> Antonio
>
>
>
>
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20150402/56e50a2a/attachment.html>


More information about the toronto-pm mailing list