Hi

Let say I have a multidimensional array and every time the number of dimensions is different. I don't have apriori information about the number of dimensions thus i need to recursively access each and figure out if there is more depth or not. But I also need to copy this array into another and modify it (let say increment). Curently I am trying to do it like this:

sub new { my ($class) = @_; my $self->{_mtx_} = []; bless $self, $class; return $self; } sub copycomp_matrix { my ($self, $arg) = @_; $self->_recurse($arg,$self->{_mtx_}); print Dumper($self->{_mtx_}); } sub _recurse { my ($self, $in, $out) = @_; for (my $i = 0;$i<@{$in};$i++){ if (ref $in->[$i] eq 'ARRAY'){ $self->_recurse($in->[$i], $out->[$i]); }else{ if (!$out->[$i]){ $out->[$i] = $in->[$i] ; }else{ $out->[$i] = $in->[$i] +1 ; } } } } ######################################################### use strict; use lib "./"; use Above::Obj; my $z = Above::Obj->new(); my $a = [[1,2],[2,3]]; $z->copycomp_matrix($a);
but I keep getting  $VAR1 = []; What am i missing ?? Is there a better way to do this ? thnx

In reply to Multidimensional arrays by baxy77bax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.