Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Set Array Columns to 0

by brx (Pilgrim)
on Jul 05, 2012 at 16:41 UTC ( [id://980112]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://980112]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-23 20:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found