On Sat, Nov 5, 2011 at 3:04 PM, Shawn H Corey <shawnhco...@gmail.com> wrote:
> On 11-11-05 01:49 PM, Uri Guttman wrote: > >> readline isn't a system call so it can't set $!. >> >> $! maps to the errno of system calls and has both the text and numeric >> values of the actual error (only if one happens) of the last system >> call. perl itself can trigger errors in system calls easily but the >> internal errors don't set $! (they do set errno internally). e.g. >> loading a file that doesn't exist will generate a perl error (which can >> be caught with eval BLOCK) but the value of $! will still be meaningless. >> > > I sorry but the function readline() will set $! on error. Yes. > See `perldoc readline`. $! will be undefined if no error occurs. > > No. Neither of these two are very portable, and may actually succeed on some architectures. But eh. For the latter: use 5.014; use Devel::Peek; pipe $in, $out; $out->autoflush; say { $out } "eeyup"; Dump $!; scalar readline($in); Dump $!; As you can see, readline() doesn't touch $! on success. Meanwhile, on error: use 5.014; use Devel::Peek; open my $dh, "."; #Open directory as file Dump $!; readline( $dh ); Dump $!; It does set $! -- Though strangely enough I can't get it to work with <>, which smells like a bug.