in reply to or DIE adding line number to error

open(LOG, "< $file") or do { print STDERR "Sorry, could not open $file: $!\n"; exit (1); }
or
unless (open(LOG, "< $file")) { print STDERR "Sorry, could not open $file: $!\n"; exit (1); }

Replies are listed 'Best First'.
Re^2: or DIE adding line number to error
by jhourcle (Prior) on Mar 10, 2005 at 03:09 UTC

    even easier:

    open(LOG, "< $file") or die "Sorry could not open $file\n";

    From die:

    If the value of EXPR does not end in a newline, the current script line number and input line number (if any) are also printed, and a newline is supplied. Note that the "input line number" (also known as "chunk") is subject to whatever notion of "line" happens to be currently in effect, and is also available as the special variable `$.'. See the section on "$/" in the perlvar manpage and the section on "$." in the perlvar manpage.