I have the following code snippet:
$u15 = 15; $u105 = 105; $u25 = 25; # for($k=0; $k<=12; $k++) { push @biu_z, $u105 ; } for ($j=0; $j<=26; $j++) { push @biu_yz, [ @biu_z ]; } for ($i=0; $i<=26; $i++) { push @biu, [ @biu_yz ]; } # for($k=0; $k<=12; $k++) { push @zcu_z, $u15 ; } for ($j=0; $j<=26; $j++) { push @zcu_yz, [ @zcu_z ]; } for ($i=0; $i<=25; $i++) { push @zcu, [ @zcu_yz ]; } # # problem ? # for ($k=1; $k<=12; $k++) { # for(my $i=1; $i<=5; $i++) { $biu[$i][4][$k] = $u25; } for(my $i=22; $i<=26; $i++) { $biu[$i][4][$k] = $u25; } for($i=1; $i<=4; $i++) { $biu[$i][23][$k] = $u25; } for($i=23; $i<=26; $i++) { $biu[$i][23][$k] = $u25; } # }
The first part is just creating 3d arrays "biu(i,j,k)" and "ziu(i,j,k)" and setting all the entries to 105 and 15 respectively. If I leave out all the statements after the comment problem ?, it prints out the arrays just as I expected. However, I am trying to change certain array locations to different values, as in the statments following the problem ? statement. It changes all the $i values for $biu in the rows ($j=4 and $j=23) versus just the $i values in the for statements. I believe I am missing something big on the understanding of how arrays work in perl, as I am still thinking in fortran terms. Do I need to make all the $i into my $i ? Thanks in advance

In reply to Help with multi-dimensional arrays (list of lists) by pattobw

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.