On 12-05-20 06:15 PM, David Christensen wrote:
If your subroutine needs to know how many arguments were passed, the
former style (assignment) makes this trivial.  Once @_ has been shifted
(latter style), I don't know an easy way to determine if zero or one
argument was passed (stack crawling?).

If it needs to know, assign the whole thing to an array. Otherwise, your interface is badly written and hard to understand.



But, this is Perl and there are more than two ways to do it -- you can
also access the argument array (@_) directly within your subroutine:

1.  Might save some CPU cycles and/or memory.  Be sure to benchmark this
claim, to see if it's worth the loss of clarity provided by well-named
internal variables.

Irrelevant. Do not micro-optimize. Optimize only in response to need and only after profiling to determine where to apply your efforts.


2.  Provides call-by-reference semantics -- your subroutine can modify
the caller's variables (intentionally or otherwise -- beware!).

Yes, that's why you use call-by-reference. But once you assign a value to a my variable, it is independent of other variables. It's only references that allow you to modify the caller's variables.


3.  Auto-vivifies missing arguments (?).

I'm not sure what you mean by this but I think my reply to #2 covers it.


4.  Blows up if the subroutine tries to modify read-only arguments.

Again, see my reply to #2.


--
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

        _Perl links_
offical site    : http://www.perl.org/
beginners' help : http://learn.perl.org/faq/beginners.html
advance help    : http://perlmonks.org/
documentation   : http://perldoc.perl.org/
news            : http://perlsphere.net/
repository      : http://www.cpan.org/
blog            : http://blogs.perl.org/
regional groups : http://www.pm.org/

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to