Hi, My understanding is of the above problem is to split the matrix to an expected order. And my code is:

sub splitMatrix {
my $val = shift;
my $order = shift;
my ($i, $i1, $j, $j1, $k, $k1, $orgRowOrder, $orgColOrder, @retval);
$orgRowOrder = scalar(@{$val});
$orgColOrder = scalar(@{$$val[0] });
for ( $i = 0, $j = 0; $j < $orgRowOrder; $j++ ) {
$i1 = $i;
for ($k = 0 ; $k < $orgColOrder; $k++) {
$j1 = $j % $order;
$k1 = $k% $order;
$retval[$i1] [$j1] [$k1] = $$val[$j] [$k] ;
$i1++ if ( $k % $order == $order-1 );
$j1++ if ( $i1 % $order == $order-1 );
$k1++;
}
$i += $order+1 if ( $j % $order == $order-1);
}
return @retval;
}

my @matrix = ([3, 4, 10, 2,2,2] ,
[2, 7, 12, 3,2,2] ,
[0, 3, 4, 5,2,2] ,
[6, 5, 9, 11,2,2] );

my ($a,$b,$c,$d,$e,$f);
($a,$b,$c,$d, $e, $f) = &splitMatrix(\@matrix,2);


print "\n1: ";
foreach my $temp ( @$a ) {
foreach my $temp2 ( @$temp ) {
print $temp2 ,"|\t";
}
print "\n ";
}

print "\n2: ";

foreach my $temp ( @$b ) {
foreach my $temp2 ( @$temp ) {
print $temp2 ,"|\t";
}
print "\n ";
}


email: indragoby@yahoo.com

In reply to Re: for loop by indragoby
in thread for loop by texuser74

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.