Perl does not provide a mechanism to check if readline returned an error. Wasn't this thread about finding one? My earlier posts show that I didn't find one.
| [reply] [d/l] |
| [reply] |
Perl 6 pretty much solves the "errno" problem by using "interesting values of undef" to convey the reason the undef is undefined,
if you happen to call something like readline in a scalar context. However, most such generators will be called using for rather than while, which will naturally distinguish end of list from exceptions that should be thrown, since the default action in Perl 6 is to throw an exception when it is determined that no one is checking for it directly, and generators used in list context don't generally want to poke exceptions into the list. Other interesting changes in Perl 6 include the fact that $! is lexically scoped, not a global alias to errno. Error values are propagated to an outer dynamic scope's $! when the decision is made whether to throw an exception or return an unthrown exception. It is hoped that this will prevent all the problems of trying to shadow C's idea of errno directly, since that's arguably one of the areas where the design of Unix was rather botched in the name of simplicity. Also, by and large, $! is treated as merely informative and useful for interpolation, but the actual underlying mechanisms do not rely on it directly, since the actual information is in whatever exception is propagating, either by explicitly being thrown, or by being returned in an interesting undef. $! is viewed as merely a handy reference to whatever the "current" error is.
| [reply] |
The while (defined(my $line = <FH>)) idom complicates things further.
| [reply] [d/l] |
Actually, this thread is about the best way to handle errors, not whether or not there is a way. I assumed the readline doc is correct. In my experience on unix, it is. I can't explain why Windows perl behaves as it does, but there is a lot I can't explain about Windows.
| [reply] |