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

Re: Don't patch perlopentut: rewrite it completely

Thread Previous | Thread Next
From:
Dr.Ruud
Date:
February 17, 2013 18:39
Subject:
Re: Don't patch perlopentut: rewrite it completely
Message ID:
20130217183902.20139.qmail@lists-nntp.develooper.com
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.

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

Maybe test $handle->error?

-- 
Ruud


perl5.8.8 -MIO::Handle -wle '
   open my $fin, "<", "not-there";
   $fin->error and print map "$_\n", $!, $^E, $@, $?;
'
Invalid argument
Invalid argument

0


$ perl5.14.2 -wle '
   open my $fin, "<", "not-there";
   $fin->error and print map "$_\n", $!, $^E, $@, $?;
'
Invalid argument
Invalid argument

0


$ perl5.14.2 -wle '
   open my $fin, "<", "not-there";
   $fin->opened or print map "$_\n", $!, $^E, $@, $?;
'



0

(huh? cleared globals?)


$ perl5.14.2 -wle '
   open my $fin, "<", "not-there";
   $fin->opened or $fin->error and print map "$_\n", $!, $^E, $@, $?;
'
Invalid argument
Invalid argument

0


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About