develooper Front page | perl.perl5.porters | Postings from May 2008

Re: bug in if(open(my $fh,...))

Thread Previous | Thread Next
From:
David Landgren
Date:
May 8, 2008 13:55
Subject:
Re: bug in if(open(my $fh,...))
Message ID:
482368E4.9020808@landgren.net
Renée Bäcker wrote:
> Dr.Ruud wrote:
>> Matt Sergeant schreef:

>> That's another bug. The "if (1) {}" can be optimized away, but should at
>> least leave a (scoping) block.
>>
>>   
> 
> B::Deparse says, that there is a do block:
> 
> rbaecker@test ~/ $ perl -MO=Deparse if.pl
> use warnings;
> use strict 'refs';
> do {
>    if (open my $fh, '/etc/passwd') {
>        print 'inner';
>    }
> };

I believe that's an expedient hack on behalf of B::Deparse, rather than 
a do block in the optree.

% perl -MO=Concise -e 'if(1) {open my $fh, "-"}'
8  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 4 -e:1) v ->3
-     <@> scope vK ->8
-        <0> ex-nextstate v ->3
7        <@> open[t3] vK/2 ->8
3           <0> pushmark s ->4
5           <1> rv2gv[t2] sK/DREFSV,1 ->6
4              <0> padsv[$fh:1,2] sM/LVINTRO ->5
6           <$> const(PV "-") s ->7
-e syntax OK

% perl -MO=Concise -e 'do {open my $fh, "-"}'
8  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 3 -e:1) v ->3
-     <1> null vK*/1 ->8
-        <@> scope vK ->-
-           <0> ex-nextstate v ->3
7           <@> open[t3] vK/2 ->8
3              <0> pushmark s ->4
5              <1> rv2gv[t2] sK/DREFSV,1 ->6
4                 <0> padsv[$fh:1,2] sM/LVINTRO ->5
6              <$> const(PV "-") s ->7
-e syntax OK

B::Deparse is a best-effort proposition, don't take its output as gospel.

David

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