Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: using a subroutine

by ysth (Canon)
on Aug 08, 2004 at 22:42 UTC ( #381122=note: print w/replies, xml ) Need Help??


in reply to using a subroutine

sub directs { ... &remove; }
When calling subroutines using the &, you should almost always use () also: &remove();. Not doing so gives the called routine access to the caller's @_; that is, a shift() in remove would take away one of direct's arguments. This can lead to hard-to-find bugs. &subname; without parens is only useful as an optimization in rare circumstances.

Alternatively, drop the & too, and either place the body of your subs before they are called, or use a forward declaration:  sub remove; sub declare;

Replies are listed 'Best First'.
Re^2: using a subroutine
by beable (Friar) on Aug 08, 2004 at 22:57 UTC
    Why not just place your subs whereever you like, call them from whereever you like without & and with (), and not use forward declarations either? What am I missing? Perl isn't C. This seems to work for me:
      I agree, but if you are in the habit of leaving off (), it may be easiest to predeclare.
Re^2: using a subroutine
by xjlittle (Beadle) on Aug 10, 2004 at 00:34 UTC
    Ditto, same as Brad ^

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2023-06-09 14:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (36 votes). Check out past polls.

    Notices?