graff has asked for the wisdom of the Perl Monks concerning the following question:
If I run that with no args (@ARGV empty), it sends a warning ("use of uninitialized value in open") and dies ("no such file or directory"). But then:#!/usr/bin/perl -w ## test 1: open for input open( I, $ARGV[0] ) or die $!; while(<I>) {print}
If I run that with no args, I get no warning, no die, and no output file -- no output of any sort, anywhere.#!/usr/bin/perl -w ## test 2: open for output open( O, '>', $ARGV[0] ) or die $!; print O "this is a test\n";
Now, if I rephrase that second open statement to the 2-arg version -- open( O, ">$ARGV[0]" ) or die $!; -- then I get the expected warning and dying messages.
For that matter, if I convert the first test to use a three-arg open -- open( I, '<', $ARGV[0] ) -- I don't get any warning or die (and "use warnings" doesn't help, either).
I find this a bit disturbing (same behavior on macosx 5.8.1 and freebsd 5.8.6). Am I missing something?
update: special thanks to Transient for an illuminating tour of the relevant C functions in the Perl code base.
|
|---|