in reply to an ever-available file for opening

I need to test the open function

I think it's slightly pointless to test the open function itself. If you think there's a chance that it may fail of its own accord (other than for resource acquisition issues) then you're probably worrying too hard. The test suite of perl itself ensures that it works correctly. At some point you have to take it as a given that the foundation is solid, and build upon it.

That said...

I need a file that I'm quite certain that exists

A better idea than $0 would be to open the null device (that's what it's there for). This can be done portably with the File::Spec module. You can read or write to it to your heart's content.

my $devnull = File::Spec->devnull(); open my $in, '<', $devnull or die "failed to open $devnull: $!\n";

• another intruder with the mooring in the heart of the Perl

Replies are listed 'Best First'.
Re^2: an ever-available file for opening
by moritz (Cardinal) on Jan 16, 2008 at 11:31 UTC
    Is the null device accessible in a chroot with no /dev/ mounted? I'd guess not...

    And I had some weird bugs once where /dev/null was not readable (a bug in the linux kernel Makefile had replaced /dev/null with a regular file owned by root and was not readable).

    I know these are corner cases, but that's what the question is all about, isn't it?