|No such thing as a small change|
Avoiding vivification with array sliceby jbert (Priest)
|on Sep 09, 2008 at 12:37 UTC||Need Help??|
jbert has asked for the
wisdom of the Perl Monks concerning the following question:
This surprised me in code recently:
Well, I actually ran into the issue with a foreach loop rather than a grep. I was thinking that the defined test would exclude any bits of the slice I didn't want - with no side effects. But clearly reading the value to test it's defined-ness is enough to vivify.
Does anyone have a nice, concise syntax for looping over "the first N elements of an array, without vivification"?
The best I can think of is:
which has the wart of requiring the additional variable @b.