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