|
|
|
Clear questions and runnable code get the best and fastest answer |
|
| PerlMonks |
Re: Re: Non-destructive array processingby Ovid (Cardinal) |
| on Jan 20, 2003 at 22:27 UTC ( #228509=note: print w/ replies, xml ) | Need Help?? |
|
Yes, the closure trick is clever, but I don't wonder which is faster. Aside from my assumption that it must be slower due to the function overhead in Perl, the obfuscation factor alone would cause me to eschew it. However, there's a more subtle problem at work that's going to kill many programmers. Since @_ aliases the argument list, the following two lines are equivalent:
What that means is that any processing on $r is going to affect @array. The following snippet will clarify.
The way to get around that with a closure is to do this: my $r = sub {my @a = @_; \@a}->(@array);Clearly that's not going to be faster than simply copying the array. Cheers, New address of my CGI Course.
In Section
Meditations
|
|
||||||||||||||||||||||||||||