C
cartercc
The script downloads a file named EAUSR.txt from a remote server. The
contents of the file are new each day, that is, I always have to
download a new EAUSR.txt in order to process the new data. After I
process the data, I need to delete EAUSR.txt to prepare for the next
day's download.
Here is the code I use:
1 $file = get_daily_file(); # gets EAUSR.txt
2 open INFILE, "<", $file or die "Cannot open INFILE, $!";
3 process_daily_file(); # calls a number of different subs
4 close INFILE;
5 unlink $file; # does not delete EAUSR.txt
6 exit();
Here's the problem: After the script exits, EAUSR.txt stil exists. If
I move line 5 to the beginning of the script, it works fine --
EAUSR.txt is deleted before I get each day's new file. The funny thing
is that my script has run for years deleting the file at the end, as
shown above, but a couple of days ago, I made some extensive revisions
to the script and now it doesn't work.
It's not a permissions problem. It's not because INFILE is still open
(I don't think). It's not because unlink doesn't work. I don't have
any idea why unlink doesn't work at the end, but works at the
beginning. Any ideas?
Question: is there any version of close that closes all open
filehandles? The script as a whole is about 500 lines long, and in
running opens and closes dozens of files, and I'm thinking that maybe
the reason the file isn't deleted is because I have inadvertently not
closed it, although I have paired up all calls to open with a call to
close.
TIA, CC.
contents of the file are new each day, that is, I always have to
download a new EAUSR.txt in order to process the new data. After I
process the data, I need to delete EAUSR.txt to prepare for the next
day's download.
Here is the code I use:
1 $file = get_daily_file(); # gets EAUSR.txt
2 open INFILE, "<", $file or die "Cannot open INFILE, $!";
3 process_daily_file(); # calls a number of different subs
4 close INFILE;
5 unlink $file; # does not delete EAUSR.txt
6 exit();
Here's the problem: After the script exits, EAUSR.txt stil exists. If
I move line 5 to the beginning of the script, it works fine --
EAUSR.txt is deleted before I get each day's new file. The funny thing
is that my script has run for years deleting the file at the end, as
shown above, but a couple of days ago, I made some extensive revisions
to the script and now it doesn't work.
It's not a permissions problem. It's not because INFILE is still open
(I don't think). It's not because unlink doesn't work. I don't have
any idea why unlink doesn't work at the end, but works at the
beginning. Any ideas?
Question: is there any version of close that closes all open
filehandles? The script as a whole is about 500 lines long, and in
running opens and closes dozens of files, and I'm thinking that maybe
the reason the file isn't deleted is because I have inadvertently not
closed it, although I have paired up all calls to open with a call to
close.
TIA, CC.