Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re (4): where do you put your subs

by mpeppler (Vicar)
on Mar 08, 2002 at 20:59 UTC ( [id://150423]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: where do you put your subs
in thread where do you put your subs

The parens/ampersand are not much of a problem...
I just wanted to point out that there is a side effect to not using parens on a subroutine/method call: the called subroutine "inherits" the @_ array of the caller. While most of you are probably aware of this it is something that can have some unintended consequences - hence my preference for always using the parens on subroutine calls.

Michael

Replies are listed 'Best First'.
Re: Re (4): where do you put your subs
by Juerd (Abbot) on Mar 08, 2002 at 21:08 UTC

    I just wanted to point out that there is a side effect to not using parens on a subroutine/method call: the called subroutine "inherits" the @_ array of the caller.

    Not entirely true. While &foo passes @_, foo and foo() and &foo() do not. Hence, imho for not passing @_ the best solution is to avoid the ampersand where possible (which means you pretty much only use it to create references).

    Proof:

    sub test { print "\@_: @_\n"; } @_ = qw(a b c); print 'test; # '; test; print '&test; # '; &test; print 'test(); # '; test(); print '&test(); # '; &test(); __END__ test; # @_: &test; # @_: a b c test(); # @_: &test(); # @_:

    44696420796F7520732F2F2F65206F
    7220756E7061636B3F202F6D736720
    6D6521203A29202D2D204A75657264
    

      My perl {3,4} training is showing, obviously... :-)

      Thanks for the correction.

      Michael

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://150423]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-16 18:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found