muxxum has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I was wondering if anyone can explain the difference between the outputs of two following programs. The only difference between the programs is that 0 is assigned to $! in the second program.
Program 1:
Output:stat("non_existing_file"); die "died at first stat" if -$!; stat("non_existing_file"); die "died at second stat" if -$!;
died at first stat at a.pl line 3.
Program 2:
$! = 0; stat("non_existing_file"); die "died at first stat" if -$!; stat("non_existing_file"); die "died at second stat" if -$!;
Output:
died at second stat at a.pl line 5.
If 0 is assigned to $! before the first stat, the first failed stat does not set the $!.
I also noticed that if instead of $!=0 we do a undef $!, the program behaves as the first one.
Thanks!
Back to
Seekers of Perl Wisdom