Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Multidimensional arrays

by vr (Curate)
on Mar 27, 2020 at 10:02 UTC ( [id://11114712]=note: print w/replies, xml ) Need Help??


in reply to Multidimensional arrays

To pinpoint where your code fails: at the time you recurse, the $out->[$i] is undefined. This "undefined" is assigned to lexical $out in callee, and further assignment e.g. $out->[$i] = $in->[$i] autovivifies $out as array reference, but unfortunately it has no connection whatsoever with $out in caller. To fix, replace

$self->_recurse($in->[$i], $out->[$i]);

with

$self->_recurse($in->[$i], $out->[$i] //= []);

Plus, if (!$out->[$i]) should be written if (!defined $out->[$i]), or you'll never increment zero values.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11114712]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (8)
As of 2024-04-19 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found