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

Re: improving $! usability (using autodie and readline)

Thread Previous | Thread Next
From:
Ben Morrow
Date:
June 24, 2009 07:44
Subject:
Re: improving $! usability (using autodie and readline)
Message ID:
20090624144432.GA18921@osiris.mauzo.dyndns.org
Quoth pjf@perltraining.com.au (Paul Fenwick):
> 
> Autodie can tell when an overriden readline has been called, since it uses
> the replacement code.  It could use Want (or similar) to check to see if
> that's being called in a pure boolean context, since:
> 
> 	use autodie; while (<>) { ... }
> 
> becomes:
> 
> 	while (&readline(STDIN)) { ... }
> 
> If it's being called in a pure boolean context, then I have a candidate for
> magical $_ setting.  The real test then is whether we're in a while loop by
> ourselves.  Then I only need to worry about what happens if the caller is
> using a lexical $_, and add some caching so we don't need to repeat the
> whole check for every call to readline().
> 
> Is there really really no way of testing if we're being called as the sole
> argument to while?

Yes, but not from pure-Perl, since not even B provides access to the
context stack. From XS it's relatively easy.

Ben


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