You said:
If I use the test: if(-s $filename > 0) It never returns true.

Given that fact, one of the following must be true: (a) the file exists but its directory entry indicates that it contains zero bytes, or (b) the file does not exist.

I've also tried replacing -s with -e just to see if the true/false works and it never returns true.

This seems to indicate that the path/file named in $filename really does not exist, or can't be found given the current context of the script (e.g. permissions and/or current working directory).

Have you inspected the value stored in $filename to confirm that it contains the string you were expecting? If the string assigned to $filename is a relative file path, are you certain that the script's current working directory is the correct location to start from in order to follow that path?

The CGI program creates the file that it's attempting to size...

So you say, but suppose we ask you to prove that. Did you include "... or die ..." on the statements that opened, wrote and closed that file? (You did close it before trying "-s" on it, didn't you?)

Have you gone in with a command-line shell, "cd" to the directory in question, and check for the file yourself?

And in case you're still confused, look again at perldoc -f -X: -e returns 0 or 1 (false or true) according to whether a file exists; -s returns a number greater-than-or-equal-to zero, where zero could mean "non-existent" or "existent but empty".


In reply to Re: File tests failing by graff
in thread File tests failing by dirtdart

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.