in reply to When is a hashreference a subexpresion?

From what I can see, the use of curly braces in ambiguous. I.e. it can mean the start of a block, or a hash reference.

The interpreter will try its hardest depending on the context to guess what you mean, but in this instance you have to provide a hint to the interpreter to disambiguate the brace.

sub a { +{ x } }
or
sub a { return { x } }
should do the trick. I forgot which perl doc I read this in. It think it was perlref, but I'm not sure.

Replies are listed 'Best First'.
Re^2: When in a hashreference a subexpresion?
by Anonymous Monk on Aug 09, 2006 at 08:13 UTC
    +{ x } is forcing scalar context (scalar { x };).
      Yeah, that's right. Sure it does.. Uh-huh.

      I was going to write 'perhaps you should have thought about that before you wrote it', but I imagine you did and still got it completely wrong.