Perl-Sensitive Sunglasses | |
PerlMonks |
Re^2: Undefined Array Referenceby wol (Hermit) |
on Apr 23, 2009 at 16:05 UTC ( [id://759576]=note: print w/replies, xml ) | Need Help?? |
Another interpretation would be "when ref_b runs out of data, don't do anything more to ref_a".
If this is what's needed then: Ie, if @{$ref_b} hasn't got as many members as @{$ref_a}, then at some point $ref_b->[$i] is undef, so dereference a reference to an empty array in that case. (I also tried to use || last there (ie exit the loop early) but that comes up with a "bizarre" error message.) If it's also possible for ref_b to have more members than ref_a, and the extras should be tacked on verbatim, then the range of the for loop needs to be adjusted to cover them. Here's one option which is moderately readable: Handily, extra elements appear in ref_a automatically as needed, so there's no need for a || [] on the first argument to push. Update: Re-reading the thread made me realise that because of the autovivification in ref_a, ikegami's suggestion does acheive all this (I think) but much more subtly. Too subtle for me the first time round ;-)
--
In Section
Seekers of Perl Wisdom
|
|