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

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

Thread Previous | Thread Next
From:
Paul Fenwick
Date:
June 24, 2009 00:32
Subject:
Re: improving $! usability (using autodie and readline)
Message ID:
4A41D67C.8040602@perltraining.com.au
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 Want.pm 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 (<>) { ... }

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?

All the best,

	Paul

-- 
Paul Fenwick <pjf@perltraining.com.au> | http://perltraining.com.au/
Director of Training                   | Ph:  +61 3 9354 6001
Perl Training Australia                | Fax: +61 3 9354 2681

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