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

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

Thread Previous | Thread Next
Paul Fenwick
June 24, 2009 00:32
Re: improving $! usability (using autodie and readline)
Message ID:
G'day Rafael / p5p,

Rafael Garcia-Suarez wrote:

> Indeed, Perl_newWHILEOP adds a defined() and a "$_=" if it sees the
> original readline op. There is currently no way of telling whether a
> subroutine call comes from an overriden readline, pure-perl or not.

Really?  I'm ignorant when it comes to Perl's guts, but I've noticed things
like go digging around opcodes to figure out what's going on.  Can
we do the same?

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 (<>) { ... }


	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?

All the best,


Paul Fenwick <> |
Director of Training                   | Ph:  +61 3 9354 6001
Perl Training Australia                | Fax: +61 3 9354 2681

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