On Tue, Jan 02, 2001 at 03:36:17PM -0000, Jonathan Peterson wrote:
[ on +{ ... } ]
> Is this explained in the latested Camel, because it doesn't show up in my
> pocket refernce at all....
It's almost a compile-time pragma, and I'm fairly sure it's in the camel.
Anyway, "perlop" has this to say:
Unary "+" has no effect whatsoever, even on strings. It
is useful syntactically for separating a function name
from a parenthesized expression that would otherwise be
interpreted as the complete list of function arguments.
(See examples above under the section on Terms and List
Operators (Leftward).)
and in "perlref":
3. A reference to an anonymous hash can be created using
curly brackets:
$hashref = {
'Adam' => 'Eve',
'Clyde' => 'Bonnie',
};
Anonymous hash and array composers like these can be
intermixed freely to produce as complicated a
structure as you want. The multidimensional syntax
described below works for these too. The values above
are literals, but variables and expressions would work
just as well, because assignment operators in Perl
(even within local() or my()) are executable
statements, not compile-time declarations.
Because curly brackets (braces) are used for several
other things including BLOCKs, you may occasionally
have to disambiguate braces at the beginning of a
statement by putting a + or a return in front so that
Perl realizes the opening brace isn't starting a
BLOCK. The economy and mnemonic value of using
curlies is deemed worth this occasional extra hassle.
For example, if you wanted a function to make a new
hash and return a reference to it, you have these
options:
sub hashem { { @_ } } # silently wrong
sub hashem { +{ @_ } } # ok
sub hashem { return { @_ } } # ok
On the other hand, if you want the other meaning, you
can do this:
sub showem { { @_ } } # ambiguous (currently ok, but may
change)
sub showem { {; @_ } } # ok
sub showem { { return @_ } } # ok
Note how the leading +{ and {; always serve to
disambiguate the expression to mean either the HASH
reference, or the BLOCK.