Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: how do I open each line of a text file into seperate arrays?

by Sherlock (Deacon)
on May 01, 2001 at 01:22 UTC ( [id://76757]=note: print w/replies, xml ) Need Help??


in reply to how do I open each line of a text file into seperate arrays?

I'd try something like this:
use strict; open (INPUT, "myFile.txt") || die "Couldn't open file: $!\n"; my @majorArray; while (<INPUT>) { my @minorArray = split('\|', $_); push @majorArray, \@minorArray; }
This will store a reference to each array within one big array, called @majorArray. You can then access each array like this:
my $arrayRef = $majorArray[0]; foreach my $temp (@{$arrayRef}) { print $temp,"\n"; }
or you can get at all of the contents of every array like this:
foreach my $item (@majorArray) { foreach my $subitem (@{$item}) { print $subitem,"\n"; } }
If you're having trouble with references, you might want to try checking out How do I loop over a reference to an array? or simply look up references in the documentation. Or, even more simply, push the actual array into the larger array to give yourself a two-dimensional array.

Hopefully, this'll help you get going. Good luck!

- Sherlock

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-03-29 12:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found