I wish to split a command line argument into a two dimensional array of variable sizes.
My perl knowledge is obviously limited, and Im sure this can be done...

(typical $argv = :a1:b1:c1:d1;:a2:b2:c2;:a3;:a4;:a5:b5;:a6:b6:c6;:a7:b7)
note- 7 rows use ";" delimiter, and a variable number of cols use ":" delimiter.
desired 2D array format is $squad[$row][$col]
also note- $squad[$row][0] will be null coz of a preceding delimiter, I wish to remove (shift) this if possible


I have easily split my command line argument into 1st array..
@squad = split (/;/, $ARGV[0]);

From there on I have trouble, but can you correct this for me please..

for ($row=0;$row<7;$row++) { # same as foreach $row (0..$#squad) I presume? @squad[$row] = split(/:/, $squad[$row]); # wrong syntax ?! shift(@squad[$row]); # remove 1st null eleme +nt (wrong again?!) foreach $col (0..$#{$squad[$row]}) { print "$squad[$row][$col]"; } print "\n"; }

In reply to Split into 2-D Array by Anonymous Monk

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.