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 reply to Re: Avoiding vivification with array slice
by jhourcle
in thread Avoiding vivification with array slice
by jbert
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |