Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: problem with array

by Hot Pastrami (Monk)
on Mar 14, 2001 at 04:22 UTC ( [id://64283]=note: print w/replies, xml ) Need Help??


in reply to problem with array

Your code reassigns the entire contents of the array on each loop... if you want to collect it all inone large array, try this instead:
while(<FILE>){ chomp; push @data, split(/,/,$_); }
...If you want individual arrays, you'll have to get fancier:
my @data = (); while(<FILE>){ chomp; push @data, [ split(/,/,$_) ]; }
This will make an array of arrays, accessible as such:
print data[0][0]; # prints the first element of the first line print data[4][3]; # prints the fifth element of the fourth line


Hot Pastrami

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-16 23:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found