in reply to Re^2: Best way to handle readline errors?
in thread Best way to handle readline errors?
is not the same asunless (defined( $line = <> )) { die $! if $!; # $! is only current and valid in the afterma +th of a failure last; # reached EOF }
if you should ask why?? Consider the following..$line = <>; if ($!) { print "Ohh noo, $!"; # an indefinite false-positive }
In the first operation, open succeeds and returns a TRUE value so warn() is skipped. However in the second, open fails and returns FALSE, warn is triggered spitting out a valid $!. The $! outside the expression is not trustworthy as one would infer from the documentation of $! in perlvar.$ touch test; # create the dummy $ perl -Mstrict -Wle 'undef $!; open my $fh, "<", "test" or warn "warn + : $!"; print "after : $!"' after : Inappropriate ioctl for device $ rm test; $perl -Mstrict -Wle 'undef $!; open my $fh, "<", "test" or warn "warn +: $!"; print "after : $!" warn : No such file or directory at -e line 1. after : No such file or directory
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Best way to handle readline errors?
by jrw (Monk) on Nov 20, 2006 at 20:09 UTC | |
by Firefly258 (Beadle) on Nov 22, 2006 at 12:17 UTC | |
by jrw (Monk) on Nov 28, 2006 at 01:38 UTC | |
by ikegami (Patriarch) on Nov 28, 2006 at 01:58 UTC | |
by jrw (Monk) on Nov 29, 2006 at 17:10 UTC | |
| |
by jrw (Monk) on Nov 29, 2006 at 17:13 UTC | |
| |
by Firefly258 (Beadle) on Dec 06, 2006 at 14:09 UTC |