mmcw
asked on
Show the last made file!
HEllo,
I have a directory with contains a lot of files.
The file are called:
1.html
2.html
3.html
etc.
When using a script called news a new file will be made.
For example now 4..html will be made.
What I now need is a little script taht load teh last file in this directory.
So When the file 4.html is last made, the script has to load this file
when this scripts is started!
Is this possible?
greetings Michel
I have a directory with contains a lot of files.
The file are called:
1.html
2.html
3.html
etc.
When using a script called news a new file will be made.
For example now 4..html will be made.
What I now need is a little script taht load teh last file in this directory.
So When the file 4.html is last made, the script has to load this file
when this scripts is started!
Is this possible?
greetings Michel
ASKER
The file 4.html contains html.
When I start this script the HTML code must be send to the browser.
When I start this script the HTML code must be send to the browser.
# The following code picks up the file which has the highest number prefix
# Also assuming that we have changed to the directory where the files reside
$file_to_display = (sort {$b <=> $a} glob "[0-9]*.html")[0];
# display the file to the browser
# Also assuming that we have changed to the directory where the files reside
$file_to_display = (sort {$b <=> $a} glob "[0-9]*.html")[0];
# display the file to the browser
ASKER
How do I make a little script that reads the highest number and writes it to screen
> How do I make a little script that reads the highest number and writes it to screen
OK. Here it is:
#!/usr/local/bin/perl
# change to the appropriate directory
chdir "/direcotry/where/html/fil es/reside" or die "can't chdir because $!\n";
# what is the latest file?
$latest_file = (sort {$b <=> $a} glob "[0-9]*.html")[0];
# open the file and display it
print "Content-Type: text/html\n\n"; # we are writing to a browser
open LATEST, "<$latest_file" or die "can't open $latest_file because $!\n";
while (<LATEST>) {
print;
}
close LATEST;
OK. Here it is:
#!/usr/local/bin/perl
# change to the appropriate directory
chdir "/direcotry/where/html/fil
# what is the latest file?
$latest_file = (sort {$b <=> $a} glob "[0-9]*.html")[0];
# open the file and display it
print "Content-Type: text/html\n\n"; # we are writing to a browser
open LATEST, "<$latest_file" or die "can't open $latest_file because $!\n";
while (<LATEST>) {
print;
}
close LATEST;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER