undef $! doesn't really undefine $! because defined($!) returns true after undef($!) !!

Huh? How do you get that? Doesn't work that way for me...

perl -e 'print "Output:\n"; for $i (1..3) { print "$i: ".(defined($_)? "defined\n":"not defined\n"); $_ = ($i==1) ? "":undef }' Output: 1: not defined 2: defined 3: not defined
(perl 5.8.6 on macosx/darwin)

$_ starts out as undefined until something other than undef is assigned to it, and after that, assigning undef to it appears to have the expected result.

I would think most 5.* perl versions to behave the same in this regard, so maybe you were doing things differently?

(update: oops! Sorry, I got confused about which variable was being talked about there. Thanks to jrw for setting me straight.)

warnings from <readline> sent to stderr will have to be handled in some way

Right. Open STDERR to a scalar:

open( STDERR, ">", \$stderr_log );
It might suffice just to do that, and check the length of that scalar after each "readline" operation. (If it's not empty, do something about it; and if it's appropriate to continue, reset it to an empty string before continuing.)

Also, if readline fails and returns false, you have eof($fh) that will also return false if the readline failure was due to an error (rather than end-of-file). Are you saying that you are having some problem getting that to work the way you want? (You haven't mentioned what OS you're using, or what sorts of errors you're worried about...)


In reply to Re: Best way to handle readline errors? by graff
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.