John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

A short time ago, there was discussion of Deparse doing something funny. So I thought I'd post my own funny result while it's fresh on everyone's minds.

perl -MO=Deparse -e"$x='main::'; $y='x'; print *{${$x}{$y}}{SCALAR}"
produces:
$x = 'main::'; $y = 'x'; print *{${$x;}{$y};}{'SCALAR'}; -e syntax OK
Somehow I don't thing the interior semi's belong there.

Replies are listed 'Best First'.
Re: (another?) Deparse bug
by broquaint (Abbot) on Nov 01, 2002 at 17:14 UTC
    Somehow I don't thing the interior semi's belong there.
    Since they're just statements they fit in quite nicely, and help to clarify the statement as a whole. It's really just saying "dereference the result of this statement", and it makes things a little simpler if it's made clear where each statement ends.
    HTH

    _________
    broquaint

    update: changed s/expression/statement/ as expression in the given context is inaccurate

      Interesting. It does indeed compile with the semi's there! So why can't they go just about anywhere before another delimiter, since everyting is a (sub) expression?
        So why can't they go just about anywhere before another delimiter, since everyting is a (sub) expression?
        IANALG1 so take this with a pinch of salt :)

        Semi-colons can be put after ever statement, but not every expression. If you were to put semi-colons after every expression the you couldn't build up larger expressions e.g

        # exp # exp and exp # ( (exp || exp) and (exp || exp)) foo() || $bar->() and $baz || @quux;
        So when B::Deparse sees your code it (roughly) breaks it down into the following
        print *{ # beginning of glob dereference ${ # beginning of scalar derference $x # scalar statement to be dereferenced } # end of scalar dereference {$y} # glob statement to be dereferenced (+ ${$x} ) } # end of glob statement to be dereferenced {SCALAR} # glob slot and end of print statement
        Hopefully that clears things up. I've updated my original reply as well to be a little clearer on the issue.
        HTH

        _________
        broquaint

        1 I Am Not A Language Guru

      So the thing being dereferenced is a statement, not an expression, just like the body of a loop? Hmm, but statements don't carry values...that's what makes something an expression!