On Fri, Aug 22, 2008 at 05:30:19PM -0500, Andy Colson wrote: > Moritz Lenz wrote: > > The recommended way to write such a sub is > > > > sub xsum([EMAIL PROTECTED]) { ... } > > xsum(|@x); > > Ahh, but, if I already had a list, would that flatten and then rebuild > the list, correct? (and would, effectively, make a copy of the list?) > (vs. just passing the list?) (just passing a list like that passes a > reference, right? and wont make a new copy?)
If bound to a list context (such as provided in this case by the slurpy parameter), the | is relatively useless, since the @x would flatten anyway. In other words, there's little difference between xsum(@x) and xsum(1,2,3,4,5) unless the signature tries to bind the first argument to a scalar. Whether one syntax or the other would result in less work, or whether it'd compile down to the same code, probably depends on how much the compiler guesses about the eventual signature at compile time, so I couldn't guess which would be faster. I do think xsum(@x) is probably clearer, especially if you're already thinking of it as slurpy. The use of | generally means you're trying to cheat on the scalar parameters somehow. It's not needed in list context. Larry