in reply to anonymous filehandle for overridden open sub

Looks to me that this would work with your logging code:
my $AFILE; if (open ($AFILE, "<", $file)) { # .... }

I got rid of the -e test, because open will fail if the file isn't there anyway.

updated to make use of 3-arg open, since it's safer.

Replies are listed 'Best First'.
Re^2: anonymous filehandle for overridden open sub
by tlm (Prior) on Apr 07, 2005 at 18:56 UTC

    I get no output when I run this:

    use strict; sub open { my $filehandle = shift; return CORE::open($filehandle,@_[0..$#_]); } my $file = $0; my $AFILE; if (main::open ($AFILE, '<', $file)) { print while <$AFILE>; } else { warn 'Failed'; }
    (I do get output if the condition in the if statement is
    main::open($AFILE = IO::File->new(), "<$file")
    )

    the lowliest monk