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

Re: serious PerlIO trouble :(

Thread Previous | Thread Next
From:
demerphq
Date:
March 12, 2011 10:31
Subject:
Re: serious PerlIO trouble :(
Message ID:
AANLkTimBKkbkp90eZDqyxm7DiBZwgmxJp8zhFE-_v8m7@mail.gmail.com
On 12 March 2011 12:34, David Leadbeater <dgl@dgl.cx> 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 http://rt.cpan.org/Public/Bug/Display.html?id=54777, but that's a pragma related issue, but not quite the same thing).

I think these are unrelated to Merijn's issue.

Yves

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

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