in reply to statement vs. block?

Could you try asking again? After several rereadings, I still don't know what you are saying.

There are places that require either a simple scalar or a block; other forms of statement wouldn't work there.

And there's the ambiguity between hashref-{} and block-{}.

Dunno if either of those are what you are looking for.

Replies are listed 'Best First'.
Re^2: statement vs. block?
by BrowserUk (Patriarch) on Apr 12, 2008 at 02:18 UTC

    No it's not syntactic ambiguites I'm looking for. lodin's got the gist and a couple of good examples below. I'm looking for cases where the contents of a block form, is legally acceptable with the expression form, but would behave differently in some way.

    It's mostly intellectual curiosity. I prefer the syntax of the block version of map and grep, but for really trivial expressions with high iteration counts, the introduction of a block can have a measurable, and even significant effect on performance.

    I got to wondering if it would be possible to recognise when a block was equivalent to an expression (statement) and have the compiler do away with the push/pop of scope.

    Then I got to thinking about whether there are other places where both block and expression forms exist and what would be the effect of this kind of optimisation on them. And then ... I asked the question :)


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.