Important alert: (current site time 7/15/2013 9:04:11 PM EDT)
 

article

Bypassing prototypes

Email
Submitted on: 7/29/2000 10:56:19 PM
By: Found on the World Wide Web 
Level: Beginner
User Rating: By 2 Users
Compatibility: 5.0 (all versions), 4.0 (all versions)
Views: 7973
 
     What's the difference between calling a function as &foo and foo()?

 
				

When you call a function as &foo, you allow that function access to your current @_ values, and you by-pass prototypes. That means that the function doesn't get an empty @_, it gets yours! While not strictly speaking a bug (it's documented that way in the perlsub manpage), it would be hard to consider this a feature in most cases.

When you call your function as &foo(), then you do get a new @_, but prototyping is still circumvented.

Normally, you want to call a function using foo(). You may only omit the parentheses if the function is already known to the compiler because it already saw the definition (use but not require), or via a forward reference or use subs declaration. Even in this case, you get a clean @_ without any of the old values leaking through where they don't belong.


Other 100 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

4/4/2001 4:31:00 AMNuStyle

Thanks, i didn't know that, this is the kind of info i like to read
(If this comment was disrespectful, please report it.)

 
3/18/2004 1:00:29 PMJerome A. Simon

Thanx for the info. Your link didn't work, but I found the page...
http_//www.perldoc.com/perl5.8.0/pod/perlsub.html
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.