The proper way to open()

Dominic Thoreau dominic at thoreau-online.net
Mon Jan 30 16:56:53 GMT 2012


On 30 January 2012 16:46, Roger Burton West <roger at firedrake.org> 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.
ABC*D1EFGHIJK2.LMNO3*4PQRST*ITUBE-STANDARD-ANTI-BULLSHEIT-EMAIL*U.56X



More information about the london.pm mailing list