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] |
I don't believe so (re "further", it is, of course, part of the motivation for requiring backward compatability but is not the only such motivation). I don't see how using a lexical pragma that breaks such code is anybody's problem other than the person who broke the code by adding the pragma and not fixing the affected code to conform to the new behavior. Similarly, with Perl 6, you can use Perl 5 idioms if you tell Perl 6 that the code is "Perl 5 code" or if you know that the pragma also works in Perl 6. Though, perhaps there is already Perl 6 code in the wild that does this (no, I don't know if Perl 6 still works this way or not).
| [reply] |
oh, right, forgot about the pragma bit. Nevermind!
| [reply] |