Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

(Ovid) Re: A question of style

by Ovid (Cardinal)
on Aug 23, 2000 at 03:07 UTC ( #29131=note: print w/replies, xml ) Need Help??


in reply to A question of style

I generally prefer to use parens, but be aware that the following two statements are not identical:
&mysub; mysub();
If you call a sub with empty parentheses, the called sub has an empty @_. However, if you call it with a preceding ampersand as in the first example, the current value of @_ gets passed to the sub that you call. This is most useful when calling subs from subs.

This is more than just a matter of style. If you're not aware of that difference, coming back later to maintain that code may just break it. As a result, I prefer not to use ampersands when calling a sub unless I specifically desire to pass the contents of @_ to the called sub.

Cheers,
Ovid

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://29131]
help
Chatterbox?
[sierpinski]: why is it the last index and not the first? because the length of the array becomes the index?
[sierpinski]: thanks LanX that helps
[haukex]: the first index is always 0 - $#array gives you the last index in @array
[sierpinski]: gotcha, thanks
[LanX]: length = last index +1

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (16)
As of 2017-12-13 16:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (369 votes). Check out past polls.

    Notices?