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

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

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
June 23, 2009 01:38
Subject:
Re: improving $! usability (using autodie and readline)
Message ID:
b77c1dce0906230138w45e2b08fy825f5765db4dce25@mail.gmail.com
2009/6/23 Paul Fenwick <pjf@perltraining.com.au>:
> Having said that, I just tried:
>
>        perl -MO=Deparse -Mautodie=readline -e'while (<STDIN>) { print };'
>
> and got:
>
>        use autodie (split(/,/, 'readline', 0));
>        BEGIN {
>            $^H{'guard Fatal'} = q(ARRAY(0x12d4a60));
>        }
>        while (&readline(STDIN)) {
>            print $_;
>        }
>        -e syntax OK
>
> That reveals that it's able to catch readline (so clearly I haven't been
> trying hard enough), but it loses its magic ability of setting $_ inside a
> while loop.  I would have expected the deparsed output to be:
>
>        while( defined($_ = &readline(STDIN) ) ) {
>            print $_;
>        }
>
> While one could argue that's a bug, fixing for newer versions of Perl won't
> help the existing 5.8/5.10 install base upon which autodie presently works.
>  If someone can give me pure-perl magic that allows me to detect if
> readline() is being called inside a while loop, then I'd appreciate it, as I
> can't think of any way off the top of my head.

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.

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