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

Re: Re (4): where do you put your subs

by Juerd (Abbot)
on Mar 08, 2002 at 21:08 UTC ( [id://150424]=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re: Re: Re (4): where do you put your subs
by demerphq (Chancellor) on Mar 12, 2002 at 13:23 UTC
Re: Re: Re (4): where do you put your subs
by mpeppler (Vicar) on Mar 08, 2002 at 21:17 UTC
    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://150424]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-03-28 11:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found