Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Do you know where your variables are?
 
PerlMonks  

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

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.