Last active
October 7, 2019 22:09
-
-
Save jkg/5f94e8462cfc413eac0652a114b220df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl | |
use strict; use warnings; | |
use Getopt::Std; | |
our ($opt_n, $opt_v); | |
getopts('vn:'); | |
if ( $opt_v ) { | |
warn "warning you every $opt_n lines"; | |
} | |
my $counter; | |
while (<>) { | |
$counter++; | |
unless ( $counter % $opt_n ) { | |
warn "Processed $counter lines"; | |
} | |
print $_; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
\n
at the end of warn() text suppresses the "at line N ..." after each output$_
at the end of print() can be omitted as print will implicitly use it.or
perl -ne 'BEGIN{$n=3} $c++; warn "Processed $c lines\n" unless $c % $n; print' filename.ext
-n
-- assumes while(<>) code-e
-- onelinerBEGIN {}
block will be executed once before start