in reply to Unexpected file test (-f) result on Windows

In addition to the symptom you're reporting, you have a precedence problem that you haven't spotted yet.
open FILE, ">testfile.log" || die "Unable to create file: $!";
isn't the same as
open(FILE, ">testfile.log") || die "Unable to create file: $!";
or
open FILE, ">testfile.log" or die "Unable to create file: $!";
In the first case, you will never, ever see that die. In the second and third cases, you will. Consult the Perl operator precedence table in perlop for details.

Further, you can save yourself a lot of confusion by using the three argument form of open. E.g.,

open(FILE, ">", $log) or die "$log: $!";
This allows you to pass around filenames in variables without polluting them with extraneous symbols.

Replies are listed 'Best First'.
Re: Re: Unexpected file test (-f) result on Windows
by DaveH (Monk) on Sep 19, 2003 at 15:47 UTC

    Very true: thank you. My normal idiom is:

    open FILE, "name" or die "died: $!";

    For some inexplicable reason, I used || in this test script!

    ("Yeah, right, that's what they all say!" shouts somebody at the back of the room...)

    Is the last form of open in your examples just a Perl 5.8 construct? I've not seen it used that much (then again, I don't regularly review much code, apart from on PerlMonks).

    Cheers,

    -- Dave :-)


    $q=[split+qr,,,q,~swmi,.$,],+s.$.Em~w^,,.,s,.,$&&$$q[pos],eg,print
      Is the last form of open in your examples just a Perl 5.8 construct?

      The three argument open is in 5.6. I think it was in 5.0. Perhaps someone who has one at hand can verify.

        I've just checked on the machines I have available, and it seems like a 5.6.0 onwards feature. The 5.005_03 install (which was the lowest I could find) does not mention MODE in the perldoc.

        Thanks for the feedback. I'll start using that construct from now on.

        Cheers,

        -- Dave :-)


        $q=[split+qr,,,q,~swmi,.$,],+s.$.Em~w^,,.,s,.,$&&$$q[pos],eg,print