in reply to Re^2: my (0?$a:$b): a koan
in thread my (0?$a:$b): a koan
thats the point, compare the optree of my (0?$a:$b)="X" with my ($b)="X".
Deparse has no chance to see any difference
lanx:~$ perl -MO=Concise -e 'my (0?$a:$b)="X";print $a' c <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v:{ ->3 7 <2> aassign[t3] vKS ->8 - <1> ex-list lK ->5 3 <0> pushmark s ->4 4 <$> const[PV "X"] s ->5 - <1> ex-list lK ->7 5 <0> pushmark s ->6 6 <0> padsv[$b:1,2] lPRM*/LVINTRO ->7 8 <;> nextstate(main 2 -e:1) v:{ ->9 b <@> print vK ->c 9 <0> pushmark s ->a a <0> padsv[$a:1,2] l ->b -e syntax OK
lanx:~$ perl -MO=Concise -e 'my ($b)="X";print $a' c <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v:{ ->3 7 <2> aassign[t2] vKS ->8 - <1> ex-list lK ->5 3 <0> pushmark s ->4 4 <$> const[PV "X"] s ->5 - <1> ex-list lK ->7 5 <0> pushmark s ->6 6 <0> padsv[$b:1,2] lPRM*/LVINTRO ->7 8 <;> nextstate(main 2 -e:1) v:{ ->9 b <@> print vK ->c 9 <0> pushmark s ->a - <1> ex-rv2sv sK/1 ->b a <#> gvsv[*a] s ->b -e syntax OK
Note line a: In the first example $a is coded as entry "$a" from a lexical pad and in the second it's the scalar value of glob *a from a symbol table.
IMHO you found a case where the compiler should better warn about undefined behavior.
Cheers Rolf
UPDATE: we had a discussion about this just few weeks ago, but I can't find it. Take this instead: 'my' with 'if 0' retains old value
UPDATE: And here the warning I'm missing:
perl -wce 'my $a if 0; print $a' Deprecated use of my() in false conditional at -e line 1. -e syntax OK
UPDATE: Found it! see A curious case of of my() and Re^4: A curious case of of my() (What is GLOBAL?)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: my (0?$a:$b): a koan
by educated_foo (Vicar) on May 04, 2011 at 21:13 UTC | |
by wind (Priest) on May 04, 2011 at 21:24 UTC |