http://www.perlmonks.org?node_id=534809

looping exercises

The following command line prints the first 560 numbers, one per line. I used it to test the second script.

perl -e 'for ($i = 1; $i <= 560; $i ++) {print "$i\n";}'

A little script to print every nth line, where n is currently 56.

#!/usr/bin/perl -w use strict; my($line) = ""; my($counter) = 0; # print every nth line of STDIN, where n is defined as: my($countTo) = 56; while ($line = <STDIN>) { $counter += 1; if($counter == $countTo) { print $line; $counter = 0; } }

Now a little different, a short script to remove the first eight lines of each 56-line page.

#!/usr/bin/perl -w use strict; # # script to remove the first eight lines after lines of a page 56 # lines long. # my($line) = ""; my($counter) = 0; my ($boolean) = 0; # print every nth line of STDIN, where n is defined as: my($countTo) = 56; my($secondCounter) = 8; while ($line = <STDIN>) { $counter += 1; if($counter > $secondCounter) { print $line; } if($counter == $countTo) { $counter = 0; } }