develooper Front page | perl.perl5.porters | Postings from February 2013

Re: Don't patch perlopentut: rewrite it completely

Thread Previous | Thread Next
Tom Christiansen
February 17, 2013 19:32
Re: Don't patch perlopentut: rewrite it completely
Message ID:
>On 2013-02-17 02:30, Tom Christiansen wrote:

>> However, if hitting EOF is an expected and normal event, you
>> would not to exit just because you ran out of input.  Instead,
>> you probably just want to exit an input loop.  Immediately
>> afterwards you can then test to see if there was an actual
>> error that caused the loop to terminate, and act accordingly:
>>      while (<$handle>) {
>>          # do something with data in $_
>>      }
>>      if ($!) {
>>          die "unexpected error while reading from $filename: $!";
>>      }

> I don't like to show a test of such a global.

Which one is that?  You have no choice.

> Only if you already know something went wrong, then you can use the 
> global's value(s).

Actually, you know something went wrong.  You got undef back from 
readline.  The question is whether there was an error or whether
it was eof.  The one and only way to know that is to check $! as 
the very very very next thing after the failed call.

>Maybe test $handle->error?

Yesterday I showed that not to work in all cases.  


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About