|
|
|
Your skill will accomplish what the force of many cannot |
|
| PerlMonks |
Re: What is the point of the & sigil for function refs?by merlyn (Sage) |
| on Feb 04, 2005 at 12:14 UTC ( #428029=note: print w/ replies, xml ) | Need Help?? |
|
The & prefix unambiguously means "this is a user-defined subroutine call coming up next". You can omit it when you are using parens after your function name and your function name doesn't conflict with a built-in, or if you've declared/defined your function before you use it and the name doesn't conflict with a built-in. The & prefix also disables prototype checking, but you shouldn't be using prototypes in the first place, so I consider that a very minor point, but if I didn't mention it, someone else would surely raise that flag. {grin} In our Learning Perl book, we suggest that you always use the ampersand when you're first learning Perl, because otherwise you'll be a bit befuddled when the following code doesn't work: Yes, you're not calling your log subroutine... you're calling the built-in "logarithm" function. Oops. -- Randal L. Schwartz, Perl hacker
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||