in reply to Re^6: Best way to handle readline errors?
in thread Best way to handle readline errors?
The errno variable is not cleared by successful system calls, but it is set by failing ones.If used numerically, yields the current value of the C errno variable, + or in other words, if a system or library call fails, it sets this v +ariable. This means that the value of $! is meaningful only immediat +ely after a failure:
In order to distinguish successful and failing system calls by the use of errno alone#!/usr/bin/perl -Wl sub doit { $! = undef; open FH, shift or die "open failure: $!\n"; print "After successful open : $!"; 1 while readline FH; print "After successful read : $!"; } doit $0, 5; doit $0, 6; doit $0, undef; __END__ ___output___ ___linux___ After successful open : Inappropriate ioctl for device After successful read : After successful open : Inappropriate ioctl for device After successful read : After successful open : Inappropriate ioctl for device After successful read : $ perl -e 'print $]' 5.008008 $ uname -a Linux cond0 2.6.17-10-386 #2 Fri Oct 13 18:41:40 UTC 2006 i686 GNU/Lin +ux $ cat /etc/issue Ubuntu 6.10 \n \l ___windows___ Name "main::FH" used only once: possible typo at read.pl line 4. After successful open : After successful read : Bad file descriptor After successful open : After successful read : Bad file descriptor After successful open : After successful read : Bad file descriptor $ perl -e "print $]" 5.008006 $ ver Microsoft Windows [Version 5.2.3790] $ type c:\boot.ini | perl -ne "print $1 if /\"(.*)\"/" Windows NT 5.2(3790.srv03.SP1.rtm.050324-1447)
|
|---|