Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

RobPayne's scratchpad

by RobPayne (Chaplain)
on Mar 07, 2006 at 02:09 UTC ( #534809=scratchpad: print w/ replies, xml ) Need Help??

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; } }
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2015-07-29 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls