Gossamer Forum
Home : General : Perl Programming :

Help, with loops

Quote Reply
Help, with loops
Hi, can anyone help?

I need help making a script that will print the #'s 30-99 in a file... starting from 30.
I know it should be easy to do...
It should print them on seperate lines, like:
30
31
32 etc...

Thanks!

------------------
Quote Reply
Re: Help, with loops In reply to
Code:
#!/usr/bin/perl

# Location of the file you want to print to.
$file = '/apache/htdocs/file.txt';

open(FILE,">$file");
$num = 30;
while ($num != 100) {
print FILE "$num\n";
$num++;
}

close(FILE);

# Print a confirmation to the browser.
print "Content-type: text/plain\n\n";
print "Done!";

exit;
Quote Reply
Re: Help, with loops In reply to
Thank you very much!

------------------
Quote Reply
Re: Help, with loops In reply to
The foreach loop is also pretty nice:

foreach $number (30 .. 99) {
print FILE $number;
}

Cheers,

Alex