in reply to open file that is not in default directory

When something seems like it's not open, then use tell. In this sample script, I used die; so, if you think that something's wrong, try this:
#!/usr/bin/perl use strict; use warnings; my $file = '/DEPENDENCIES.NEW'; open FILE, '>', $file or die "Couldn't open FILE: $!\n"; if ( tell(FILE) != -1) { print "FILE is open\n"; } else { print "FILE is not open\n"; }

Replies are listed 'Best First'.
Re^2: open file that is not in default directory
by oko1 (Deacon) on Jan 16, 2011 at 19:33 UTC

    That seems rather pointless. What will 'tell' do for you in this case that "open ... or die" doesn't? If Perl is able to assign that filehandle, it succeeds; if it's not, then it fails. The only thing I can even imagine making a difference is if the file is deleted between the 'open' and the 'tell' calls.

    -- 
    Education is not the filling of a pail, but the lighting of a fire.
     -- W. B. Yeats