in reply to Re^3: Questions about context
in thread Questions about context

... you can use a scalar de-ref/ref:
print "year is ${\((localtime)[5]+1900)}!\n";

True, but I've finally managed to get this mechanism excised from the FAQ because it is messy-looking and confusing.

Many people looking at the that code (including the authors of early versions of the FAQ) would expect the expression to be evaluated in a scalar context. It is not. The expression in \(EXPR) is evaluated in a list context. Not, of course, that this makes any difference for the + operator.

Replies are listed 'Best First'.
Re^5: Questions about context
by ysth (Canon) on Feb 02, 2005 at 06:41 UTC
    Then perhaps it would be better to advocate this approach instead of the more symmetrically beautiful "@{[]}".

    It might lead more people to learn of the weird but wonderful context properties of  \. (Sometimes people wonder why perl doesn't have a "list" operator corresponding to "scalar". The answer usually given is that it would rub the camel hair the wrong way, or that it is never needed. In point of fact it is sometimes needed when doing things like recursive calls to subroutines that return a map. And the way you spell list(EXPR) is ${\(EXPR)}.)