in reply to Re^2: A curious case of of my()
in thread A curious case of of my()

It wouldn't fix the following:

foo() and my $x; foo() or my $x; foo() && my $x; foo() || my $x; foo() // my $x; foo() ? my $x : 1;

Not to mention that some code relies on the current behaviour.

Replies are listed 'Best First'.
Re^4: A curious case of of my()
by LanX (Saint) on Apr 05, 2011 at 16:18 UTC
    > Not to mention that some code relies on the current behaviour.

    unlikely, without a new scope this would lead to warnings like

    "my" variable $x masks earlier declaration

    all these cases should be treated alike, (also see update in former post)

    AFAIK post-fix if is always internally translated into a short-circuit and.

    Cheers Rolf

      No, it doesn't, but it does warn "Deprecated use of my() in false conditional" now.

      AFAIK post-fix if is always internally translated into a short-circuit and.

      The compiled form of if and unless always use one of the and or or opcodes. There is no if or unless opcode.

      $ perl -MO=Concise,-exec -e'if (f()) { g() }' 1 <0> enter 2 <;> nextstate(main 3 -e:1) v:{ 3 <0> pushmark s 4 <$> gv(*f) s/EARLYCV 5 <1> entersub[t1] sKS/TARG,1 6 <|> and(other->7) vK/1 7 <0> pushmark s 8 <$> gv(*g) s/EARLYCV 9 <1> entersub[t2] vKS/TARG,1 a <@> leave[1 ref] vKP/REFC -e syntax OK $ perl -MO=Concise,-exec -e'if (!f()) { g() }' 1 <0> enter 2 <;> nextstate(main 3 -e:1) v:{ 3 <0> pushmark s 4 <$> gv(*f) s/EARLYCV 5 <1> entersub[t1] sKS/TARG,1 6 <|> or(other->7) vK/1 7 <0> pushmark s 8 <$> gv(*g) s/EARLYCV 9 <1> entersub[t2] vKS/TARG,1 a <@> leave[1 ref] vKP/REFC -e syntax OK