Please use use strict. Not using it hides errors, including the one you made.

use strict; use warnings; my @a=([0,1,2]); my @b=([-1,-2,-3]); unshift @a,1; # Creates an element with the value "1". $a[0][0]=4; # Changes element 0 of the array named by $a[0]. $a[0][1]=5; # Changes element 1 of the array named by $a[0]. $a[0][2]=6; # Changes element 2 of the array named by $a[0]. unshift (@b,1); # Creates an element with the value "1". $b[0][0]=7; # Changes element 0 of the array named by $b[0]. $b[0][1]=8; # Changes element 1 of the array named by $b[0]. $b[0][2]=9; # Changes element 2 of the array named by $b[0]. print $a[0][2]; # Print element 2 of the array named by $a[0]. print $a[1][2]; # Print element 2 of the array ref'ed by $a[1]. print $b[0][2]; # Print element 2 of the array named by $b[0]. print $b[1][2]; # Print element 2 of the array ref'ed by $b[1].
Can't use string ("1") as an ARRAY ref while "strict refs" in use at s +cript.pl line 8.

If you want to add a new row, use unshift @a, [ ];.

unshift @a, [ ]; $a[0][0]=4; $a[0][1]=5; $a[0][2]=6;

or

unshift @a, [ 4, 5, 6 ];
[ ] creates an anonymous array and returns a reference.

In reply to Re: unshift with two-dimensional arrays by ikegami
in thread unshift with two-dimensional arrays by eatthatquestion

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.