I did some digging (on Windows XP, using perl 5.8.8). I didn't come up with a solution, but I thought I'd post what I found out.

In all cases, I can confirm an IO error occured, since the OS pops a dialog asking to reinsert the disk once all read buffers have been emptied.

Test programs:

For <$fh>:

use strict; use warnings; my $file_name = 'G:\\I386\\DRIVER.CAB'; # 50MB file. open(my $fh, '<', $file_name) or die("Unable to open file \"$file_name\": $!\n"); # Read 100 bytes at a time. #binmode($fh); #$/ = \100; my $line; undef $!; $line = <$fh>; my $ok_defined = defined($!); my $ok_str_val = "$!"; my $ok_num_val = 0+$!; print("Eject the media then press Enter."); <STDIN>; undef $!; for (;;) { undef $!; last if not defined ($line = <$fh>); warn(length($line), "\n"); } my $bad_defined = defined($!); my $bad_str_val = "$!"; my $bad_num_val = 0+$!; close($fh) or warn("Unable to read file \"$file_name\": $!\n"); print("On success, "); if ($ok_defined) { print("\$! = \"$ok_str_val\"/$ok_num_val\n"); } else { print("\$! is not defined\n"); } print("On failure, "); if ($bad_defined) { print("\$! = \"$bad_str_val\"/$bad_num_val\n"); } else { print("\$! is not defined\n"); }

For sysread and read:

use strict; use warnings; my $file_name = 'G:\\I386\\DRIVER.CAB'; # 50MB file. open(my $fh, '<', $file_name) or die("Unable to open file \"$file_name\": $!\n"); my $buf; my $rv; $rv = sysread($fh, $buf='', 1); print("On success, "); if (defined($rv)) { print("\$rv = $rv\n"); } else { print("\$rv is not defined\n"); } print("Eject the media then press Enter."); <STDIN>; 1 while $rv = sysread($fh, $buf='', 1); print("On failure, "); if (defined($rv)) { print("\$rv = $rv\n"); } else { print("\$rv is not defined\n"); } close($fh) or warn("Unable to read file \"$file_name\": $!\n");

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