I've got the following bit of code, but I can't seem to get it to work reliably...
use strict;
use warnings;
use CGI::Carp 'fatalsToBrowser';
use CGI qw/:standard/;
my $FileName = "ADD.DEL";
my $FileAge = -M $FileName;
if ($FileAge < 1.0) {
open(CHECK, "<count.ct") or die "Where be me count file, mon \n";
my @text = <CHECK>;
close(CHECK);
my $count = @_;
if ($count eq "0") {
print "content-type: text/html\n\n";
print '<html><body><h1>Get File</h1><br>';
print '</body></html>';
}
if ($count eq "1") {
print "content-type: text/html\n\n";
print '<html><body><h1>Dont Get File</h1><br>';
print '</body></html>';
}
}
Any pointers on where my syntax is screwed up?
Right now it only returns the "get file" part regardless of what the count file is set to.
The File Age bit works okay, the problem I have is getting it to recognize the difference between a "1" and a "0".
My next step was to add something like:
select(CHECK);
print "1";
close (CHECK);
I added this to the "0" part of the if/then statement, and it opened the count file and wrote in a "1" but I got an ISE.
Here is what the overall goal is, but I really want to learn *why* I'm doing what I'm doing:
1. Script Runs
2. Checks age (in days) of another file on the same server
3. If age in days is more than 1 day old
4. Check count file
5. If count file contains 1, stop and run rest of script
6. If count file contains 0, open count file write a 1 to it
7. AND then FTP to remote server and check date of remote files, if remote files have same date as local files, stop and run rest of script
8. If remote files have different date than local file retrieve from remote server, open count file, write a 0 to it and run rest of script.
(I've got the ftp part to work and the age of the file part to work.)
Any help is really appreciated!
.
Code:
#!/usr/local/bin/perl use strict;
use warnings;
use CGI::Carp 'fatalsToBrowser';
use CGI qw/:standard/;
my $FileName = "ADD.DEL";
my $FileAge = -M $FileName;
if ($FileAge < 1.0) {
open(CHECK, "<count.ct") or die "Where be me count file, mon \n";
my @text = <CHECK>;
close(CHECK);
my $count = @_;
if ($count eq "0") {
print "content-type: text/html\n\n";
print '<html><body><h1>Get File</h1><br>';
print '</body></html>';
}
if ($count eq "1") {
print "content-type: text/html\n\n";
print '<html><body><h1>Dont Get File</h1><br>';
print '</body></html>';
}
}
Any pointers on where my syntax is screwed up?
Right now it only returns the "get file" part regardless of what the count file is set to.
The File Age bit works okay, the problem I have is getting it to recognize the difference between a "1" and a "0".
My next step was to add something like:
Code:
open(CHECK, ">count.ct") or die "I canna be a writin lassie \n"; select(CHECK);
print "1";
close (CHECK);
I added this to the "0" part of the if/then statement, and it opened the count file and wrote in a "1" but I got an ISE.
Here is what the overall goal is, but I really want to learn *why* I'm doing what I'm doing:
1. Script Runs
2. Checks age (in days) of another file on the same server
3. If age in days is more than 1 day old
4. Check count file
5. If count file contains 1, stop and run rest of script
6. If count file contains 0, open count file write a 1 to it
7. AND then FTP to remote server and check date of remote files, if remote files have same date as local files, stop and run rest of script
8. If remote files have different date than local file retrieve from remote server, open count file, write a 0 to it and run rest of script.
(I've got the ftp part to work and the age of the file part to work.)
Any help is really appreciated!
.