develooper Front page | perl.perl5.porters | Postings from June 2009

improving $! usability (was: Re: 1b7a0411f8b7cab [...] set errno)

Thread Next
From:
Stepan Kasal
Date:
June 19, 2009 03:42
Subject:
improving $! usability (was: Re: 1b7a0411f8b7cab [...] set errno)
Message ID:
20090619104232.GA26914@camelia.ucw.cz
Hello,

On Thu, Jun 18, 2009 at 10:57:10PM -0500, Craig A. Berry wrote:
> On Thu, Jun 18, 2009 at 9:03 AM, Stepan Kasal<skasal@redhat.com> wrote:
> > I thought that checking $! immediately after the last read is the
> > way.
> 
> But only if the last read does not hit EOF.  In other words, if
> readline() returns undef AND you are not at EOF, then $! is likely to
> contain something useful.  Otherwise who knows.  The docs were
> clarified quite recently:
> 
> <http://perl5.git.perl.org/perl.git/commitdiff/d947e7a>

than the following quote from perlfunc might need to be corrected as
well:
"Practical hint: you almost never need to use C<eof> in Perl, because the
input operators typically return C<undef> when they run out of data, or if
there was an error."

More seriously speaking, the eof flag might mask an actual error.

Perhaps the perl interpreter should make sure that eof is unset if an
error appears, so that we can look at it.

Or should we rather introduce ferror to perl?  Wouldn't that be
against the plan to have perl io "a cleaned up version of stdio"?

Better yet, wouldn't it be possible to make sure that $! is not set
by a successful io operation?
Either It could be cleared after every successful io operation.
(Or the value could be saved before the io call and then restored if
the io was successful, so that backward compatibility with broken
perl code is maintained.)

Regards,
	Stepan

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