"be consistent" | |
PerlMonks |
Re: Avoiding vivification with array sliceby jhourcle (Prior) |
on Sep 09, 2008 at 14:04 UTC ( [id://710092]=note: print w/replies, xml ) | Need Help?? |
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. You're testing too late. Besides betterworld's trick, or moritz's optimization, you could specifically test for defined-ness per element, rather than taking the slice first: @b = map { defined($a[$_]) ? ($a[$_]) : () } (0..5);
In Section
Seekers of Perl Wisdom
|
|