The proper way to open()

Dominic Thoreau dominic at
Mon Jan 30 16:56:53 GMT 2012

On 30 January 2012 16:46, Roger Burton West <roger at> wrote:
> What's a good way of opening a file as read-only, and failing if it
> doesn't exist? open() just returns a handle that's not obviously
> invalid, which strikes me as odd behaviour. At the moment I'm doing
> something like:
>  open IN,"<$cfg";
>  if (eof IN) {
>    die "bad config file $cfg\n";
>  }

open IN, '<', $cfg || handle_that_error_sub;

# where sub handle_that_error itself calls die with $! . Also gives
you some possibility of doing cleaningup.

Nonnullus unus commodo reddo is mihi.

More information about the mailing list