frogsausage has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks! Happy Monday everyone!
I am writing (or debugging now) a Perl script which at one point creates a file: creating an array, then printing it out through a filehandle. Therefore, I want to check if my file is present and not empty. For that I get the full path using rel2abs, which is working fine, then doing a
if (-s $myAbsPathToFile) {print "Good to go"} else {print "File is missing"};Surprisingly, the same script behaved differently when running on these two configurations:
- SuSE 10 + Perl 5.8.5 (says "Good to go")
- SuSE 11 + Perl 5.14.1 (says "File is missing")
To test that, I wrote the following small script:
print "Matched" if (-s "/home/frogsausage/file");Where "file" is a non-empty file in my ~
Output will be "Matched" on SuSE 10 (Perl 5.8.5) and... nothing on SuSE 11 (Perl 5.14.1) Actually it is "Matched on both with that small script, but when running my file it full script, it doesn't work :(.
I ran it on my Mac at home (10.6.8 + Perl 5.8.8 / Perl 5.14.1 installed using macports) and it printed "Matched" for both Perl version. That was a debug before I could run it again on the SuSE machine.
I also had a look at the perlport for 5.14.1 and couldn't find anything related to my issue.
-s and ! -z behave the same (not talking 'logically' here), meaning "File is missing" in the script. -e works fine.
Any ideas? Looking forward to some hints here.
Note that I cannot change the perl version by installing a new one. Also, I don't want the user to have to check anything prior running the script, meaning, it should run the same piece of script for both Perl 5.8.5 to Perl 5.14.1 (at least), as well as SuSE 10/11. Code is pretty simple and that is the only error I've found.
Update from the thread:
- on SuSE 11/Perl 5.14.1 error is 'No such file or directory' while it works on the SuSE 10 machine.
- file is located at the same place regarding the OS (NFS drive)
Update 2:
- Adding an extra empty system() statement before the file test made it work. No ideas why though. Hidden Perl variable messing up with it?
Last update and solution:
- The problem was caused by the filehandle for the file still being open. The file was created using the 'print' statement in my case.
- Thanks richardK, thanks all, for the useful hints and solution!
|
|---|