in reply to Parse txt file into array of array
G'day Dr Manhattan,
You were almost there. You need to push an arrayref (not an array) of the split characters. Here's my test:
#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; my @MainArray; while (<DATA>) { chomp; push @MainArray, [ split // ]; } print Dumper \@MainArray; __DATA__ Hello my name is Jack
Output:
$ pm_file_chars_to_AoA.pl $VAR1 = [ [ 'H', 'e', 'l', 'l', 'o' ], [ 'm', 'y' ], [ 'n', 'a', 'm', 'e' ], [ 'i', 's' ], [ 'J', 'a', 'c', 'k' ] ];
See also: perldsc - Perl Data Structures Cookbook
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parse txt file into array of array
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 |