On day9/3/01 at 3:23 pm -0800, Christopher Palmer wrote:

>another question on this...I have the loop in place, but it still 
>prints the entire file to the screen...not the specified number of 
>lines...hmmmmph!
>
>$j = 0;
>while ($j < 10) {
>while ( $line = <THATFILE>) {
>print "$line\n";
>$j++;
>}
>}

Try this:


#!perl
$dir = $ENV{TMPDIR}; mkdir $dir, 0;
$f = "$dir:temp.txt";
# write 25 lines to new file $f
open F, ">$f";
for ($n = 1; $n < 25; $n++) {print F "Line $n\n";}

# print first ten lines of $f
open F, $f;
while (<F>) {$i < 10 and print or last; $i++;}


JD

Reply via email to