in reply to How do i count lines from data file?
Use the $. global variable.
while (<>) { my_sub() if $. > $allowedlines; print; # do the rest of your stuff }
As an alternative, you can set a variable yourself, for example if you need to reset the counter.
my $count =0; while (<>) { if ($count++ > $allowedlines) { my_sub(); $count =0; } print; # do the rest of your stuff }
See perldoc perlvar for more info on $.
|
|---|