develooper Front page | perl.perl5.porters | Postings from March 2011

Re: serious PerlIO trouble :(

Thread Previous | Thread Next
March 12, 2011 10:31
Re: serious PerlIO trouble :(
Message ID:
On 12 March 2011 12:34, David Leadbeater <> wrote:
> On 12 Mar 2011, at 10:09, H.Merijn Brand wrote
> [...]
>>> Presumably because the open pragma isn't applying inside IO::Handle
>> Should it? Should I file an RT?
> IMHO it should, considering how IO::Handle is part of the core and is used transparently (even more so now IO::File will be loaded on demand without an explicit use).

I don't think this is a bug really. use open would be lexically
scoped, and ARGV isnt being opened in the scope of the use open
pragma, it is being opened in the scope of the the getline() sub, or
in other words it is being called in the scope of IO::Handle.

I think we document that "<>" is magic anyway, and that its behaviour
is a bit special. So

while (my $r = *ARGV->getline) {
          print $r;

is not at all the same thing as

while (<>) {
   print $_;

Rather you want:

while (@ARGV) {
   $ARGV=shift @ARGV;
   open ARGV or die "Failed to open $ARGV: $!";
   while (my $r= *ARGV->getline) {
      push @lines,$line;

> A very similar issue applies to the autodie pragma (binmode just a random example here, not limited to that):
>  $ bleadperl -Mautodie -e'STDIN->binmode(":x")'
>  [you do get a warning here if you turn on warnings, else nothing.]
>  $ bleadperl -Mautodie -e'binmode STDIN, ":x"'
>  Unknown PerlIO layer "x" at (eval 31) line 67.
>  Can't binmode('STDIN', ':x'): No such file or directory at -e line 1
> Not sure if there's an RT for that already? (I see, but that's a pragma related issue, but not quite the same thing).

I think these are unrelated to Merijn's issue.


perl -Mre=debug -e "/just|another|perl|hacker/"

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