in reply to Avoiding vivification with array slice
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);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Avoiding vivification with array slice
by jbert (Priest) on Sep 09, 2008 at 14:45 UTC | |
by ikegami (Patriarch) on Sep 09, 2008 at 19:45 UTC |