perl.org wrote: > On Wed, 14 Jul 2004 15:45:52 -0400, Bob Showalter wrote > > perl.org wrote: > > > > > > I still don't understand the reasoning for this - how could adding > > > more to the sub signature be worse than not having any? > > > > This is explained in perldoc perlsub. > > What section are you referring to?
This section: It's probably best to prototype new functions, not retrofit prototyping into older ones. That's because you must be especially careful about silent impositions of differing list versus scalar contexts. For exam- ple, if you decide that a function should take just one parameter, like this: sub func ($) { my $n = shift; print "you gave me $n\n"; } and someone has been calling it with an array or expression returning a list: func(@foo); func( split /:/ ); Then you've just supplied an automatic "scalar" in front of their argu- ment, which can be more than a bit surprising. The old "@foo" which used to hold one thing doesn't get passed in. Instead, "func()" now gets passed in a "1"; that is, the number of elements in "@foo". And the "split" gets called in scalar context so it starts scribbling on your "@_" parameter list. Ouch! Follow Randal's advice if you don't like mine :~) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>