PDA

View Full Version : Simple bit of code to add please.



Sscotties
08-22-2002, 01:08 PM
#!/usr/bin/perl

# HOW DO I DO THIS ?:
# open up a local *.txt file (eg. in 'cgi-bin')
# get the value of an integer there
# increment it by 1 in the external file and
# assign the variable $i the new value
# THEREFORE ...
# reading page1.txt, page2.txt, page3 etc,

$address = "/public_html/page+$i+.txt";
open(OUT, ">$address");
print "content-type: text/plain\n\n";

while (<>) {
print OUT $_;
print $_;
}
close (OUT);
exit 0;

mr_ego
08-23-2002, 06:41 AM
You could try this:



#!/usr/bin/perl

$i = 0; # what the page you want to start at is

# "-e" is a command interprating to "does it exist?"

while (-e "/cgi-bin/page$i.txt") {
# whatever you want to do when the file is opened:
# eg:
# open(FILE,"/cgi-bin/page$i.txt");
# @file = <FILE>; close(FILE);
# foreach $file (@file) { print $file; }

++$i; # Do not remove this! Increases the $i value.
}

print $i; # shows the total number of files opened.



Note. If you are going to this above, you can not declair the variable $address and expect it to work as it wont update.

Sscotties
08-23-2002, 11:19 AM
Thanx chief ego, it looks perfect.