in reply to Set Array Columns to 0
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
|
|---|