in reply to how does splice do it?

++ LanceDeeply for sensible question, ++ Zaxo's consise answer.
Methinks many places I am passing references I could be using prototypes.
Thankyou.
Update: OK , I am justly chastised , just because this feature exists is no carte-blanche reason to be using it.

I can't believe it's not psellchecked

Replies are listed 'Best First'.
Re ^2: how does splice do it?
by Coruscate (Sexton) on Jan 09, 2003 at 23:26 UTC

    Do be careful with using prototypes vs. passing references. IMHO, code is much more readable and maintainable if you make a habit of passing references. In this manner, you don't have to look at the subroutine declaration to see what arguments it expects.

    It seems to me that some core perl functions, such as splice, push, pop, shift and unshift use prototypes because the name of the functions as well as the way they are called read easier in the english language. "Push onto this array the following list" rolls off the tongue better than "Call the push() function with a reference and a list to add to it". push \@array, @list; just doesn't look right. Whenever I see a call to a subroutine with an array as the first argument, I generally assume that a copy of an array is being passed to the subroutine and that each item in the array will fill @_, not that it will all be within $_[0].

    It all comes down to a matter of preference, but I'd like to think that more people stick to passing references than creating a prototype for every subroutine they write. I'd be interested in hearing other opinions on this matter. Which method of passing arguments do you use more frequently and why?

      ...and why?

      Prototypes don't work for method calls. So, they are generally useless for an alternative to passing a reference.

        Please don't assume that everyone lives in an OO world. I came to Perl from a non-OO background, and rarely build my own classes. I'm just more comfortable with function calls, and have a big enough ego to assume that somewhere, someone else does the same thing. TIMTOWTDI.

        --
        Spring: Forces, Coiled Again!