[Israel.pm] Direct access to variables from sub

david istermann interdist at gmail.com
Sun Oct 2 06:49:21 PDT 2005


Gaal, thank you for clearing all this stuff. Sometimes I am being
amazed how code in Perl can be extremely shortened and at the same
time made hardly readable...

Levenglick Dov-RM07994 wrote:
> This is the first time I hear of this magical + operator. What exactly does it do
> and where can I find the proper documentation

"Programming Perl" states that :

Since braces are also 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. For
example, if you want a function to make a new hash and return a
reference to it, you have these options:
        sub hashem {        { @_ } }     # Silently WRONG -- returns @_.
        sub hashem {       +{ @_ } }    # Ok.
        sub hashem { return { @_ } }   # Ok.

David.




More information about the Perl mailing list