idunno has asked for the wisdom of the Perl Monks concerning the following question:

What's the difference in calling a subroutine like dostuff() and like &dostuff ?
Which should I use?

Thanks for your help.

Replies are listed 'Best First'.
(Ovid) Re: How to call a function
by Ovid (Cardinal) on Apr 27, 2001 at 20:26 UTC
    Calling a function with empty parens, dostuff(), passes an empty parameter list. The @_ array in the called function will be empty. Of course, by putting parameters in the parens, you will pass them.

    Calling a function with the ampersand, &dostuff, will pass the current contents of @_ to the called sub. This can be very useful for exception handling, OO programming, or perhaps if you rename a function but want to keep the old function around because others are still using your code.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: How to call a function
by Albannach (Monsignor) on Apr 27, 2001 at 20:26 UTC
    Here is a good summary.

    --
    I'd like to be able to assign to an luser