in reply to Re: Testing <> for undefined
in thread Testing <> for undefined

I have done this in the past, and it seems to work fine:
my $file = $ARGV[0] ? $ARGV[0] : die "USAGE:  prog.pl file_pathname\n";
open(FILE,"$file") or die "Unable to open file $file\n";

Replies are listed 'Best First'.
Re^3: Testing <> for undefined
by Roy Johnson (Monsignor) on Jul 08, 2004 at 16:57 UTC
    I have to say that I hate your use of the trinary operator there. You're expressing that you want to assign die's result to $file. Instead:
    my $file = $ARGV[0] or die "Usage: prog.pl file_pathname\n";
    (as a bonus, you don't have the redundant mention of $ARGV[0]).
    Better, if the filename might be zero:
    @ARGV or die "Usage: prog.pl file_pathname\n"; my $file = $ARGV[0];

    We're not really tightening our belts, it just feels that way because we're getting fatter.