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!


In reply to -s test option returns differently in some cases by frogsausage

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.