When you split the line, the result can be a list which contains less elements than you are expecting.

Thurs,July,5,2012,123,456,789 : here you'll obtain 7 elements, no more.

So, do not trust the input and don't forget to chomp your lines.

Here, I'm using an additional list of 11 empty string ("" is not undef) to be sure that all (11) variables are defined.
#!perl use strict; use warnings; my @array=<DATA>; chomp @array; my $line; my ($dow,$mon,$day,$year,$num1,$num2,$num3,$dow2,$mon2,$day2,$year2); foreach $line (@array){ ($dow,$mon,$day,$year,$num1,$num2,$num3,$dow2,$mon2,$day2,$year2) += ((split /[,]/, $line),("")x11); print "$dow2\n"; } __DATA__ Thurs,July,5,2012,123,456,789 Thurs,July,5,2012,123,456,789,Fri,July,6,2012

In reply to Re: Set Array Columns to 0 by brx
in thread Set Array Columns to 0 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.