Well, if you ran my test program (see above) on unix and got different results than I did, then I will have to defer to an observable fact that different versions of perl handle this differently. But on all the unix machines I've tested this on, it is 100% consistent (I will concede that Windows perl handles this differently).

Plus, the docs for $! state "after a failure". There is no definition for "failure" given, but I assume it means after readline returns undef, which it does on both EOF and I/O error. Therefore, it is valid to check the value of $! in the case under consideration, since readline has returned undef.

Could you please post the output of "uname -a" on the version of unix where you ran my test program and the version of perl you used to run it? Here are my results for a variety of perl versions and unices, plus Windows XP. The only version that displays the strange behavior of modifying $! on EOF is Windows XP.

AIX 5.2 This is perl, version 5.005_03 built for aix n=5 s=I/O error n=6 s=No such device or address n=0 s= This is perl, v5.8.0 built for aix-thread-multi n=5 s=I/O error n=6 s=No such device or address n=0 s= AIX 5.3 This is perl, v5.8.2 built for aix-thread-multi n=5 s=I/O error n=6 s=No such device or address n=0 s= SunOS 5.8 This is perl, version 5.005_03 built for sun4-solaris n=5 s=I/O error n=6 s=No such device or address n=0 s= This is perl, v5.6.0 built for sun4-solaris n=5 s=I/O error n=6 s=No such device or address n=0 s= SunOS 5.9 This is perl, version 5.005_03 built for sun4-solaris n=5 s=I/O error n=6 s=No such device or address n=0 s= This is perl, v5.6.0 built for sun4-solaris n=5 s=I/O error n=6 s=No such device or address n=0 s= This is perl, v5.6.1 built for sun4-solaris-64int n=5 s=I/O error n=6 s=No such device or address n=0 s= Linux 2.4.2-2 This is perl, v5.6.0 built for i386-linux n=5 s=Input/output error n=6 s=No such device or address n=0 s= Linux 2.4.21-47.0.1.ELsmp This is perl, v5.8.0 built for i386-linux-thread-multi n=5 s=Input/output error n=6 s=No such device or address n=0 s= CYGWIN_NT-5.1 1.5.19(0.150/4/2) This is perl, v5.8.7 built for cygwin-thread-multi-64int n=5 s=Input/Output error n=6 s=No such device or address n=0 s= Windows XP This is perl, v5.8.7 built for MSWin32-x86-multi-thread n=0 s= n=0 s= n=0 s=

In reply to Re^8: Best way to handle readline errors? by jrw
in thread Best way to handle readline errors? by jrw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.