Dr Manhattan has asked for the wisdom of the Perl Monks concerning the following question:
Hi all
I want to parse a text file into an array of array, one line per small array, one letter per element of small array
So if I have a text file containg:
Hello
my
name
is
Jack
The array has to look like this:
@MainArray element 1 ---> elements of small array ---> H, e, l, l, o
@MainArray element 2 ---> elements of small array ---> m, y
@MainArray element 3 ---> elements of small array ---> n, a, m, e
@MainArray element 4 ---> elements of small array ---> i, s
@MainArray element 5 ---> elements of small array ---> J, a, c, k
I have something along these lines, but I don't how to add the part where each new line in the text file is added as a new small array in @MainArray. All this does is add every letter to one large @MainArray
open (A1, "<2 normaal.txt") or die "can't open"; my @MainArray; while (<A1>) { my $in = $_; chomp $in; push (@array1, split(//, $in)); }
Thanks in advance for any help, much appreciated
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parse txt file into array of array
by kcott (Archbishop) on Jun 06, 2013 at 10:01 UTC | |
by Dr Manhattan (Beadle) on Jun 06, 2013 at 17:57 UTC | |
by kcott (Archbishop) on Jun 06, 2013 at 20:30 UTC | |
by Dr Manhattan (Beadle) on Jun 07, 2013 at 07:55 UTC | |
by kcott (Archbishop) on Jun 07, 2013 at 09:48 UTC | |
by hdb (Monsignor) on Jun 06, 2013 at 18:42 UTC | |
|
Re: Parse txt file into array of array
by jwkrahn (Abbot) on Jun 06, 2013 at 10:31 UTC | |
|
Re: Parse txt file into array of array
by hdb (Monsignor) on Jun 06, 2013 at 09:49 UTC | |
|
Re: Parse txt file into array of array
by hdb (Monsignor) on Jun 06, 2013 at 10:52 UTC |