in reply to Re^2: Parse txt file into array of array
in thread Parse txt file into array of array
I see hdb has shown the syntax you requested. Be aware that splice can be slow and there are often better alternatives. For instance, if you had intended to use splice to remove lowercase characters, you could have rewritten that entire block of code above as:
for (@MainArray) { @$_ = grep { ! /[a-z]/ } @$_; }
Here's my test:
#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; my @MainArray; # Original array populating code while (<DATA>) { chomp; push @MainArray, [ split // ]; } # New alternative to 'splice' code for (@MainArray) { @$_ = grep { ! /[a-z]/ } @$_; } print Dumper \@MainArray; __DATA__ Hello my name is Jack
Output:
$ pm_file_chars_to_AoA_2.pl $VAR1 = [ [ 'H' ], [], [], [], [ 'J' ] ];
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Parse txt file into array of array
by Dr Manhattan (Beadle) on Jun 07, 2013 at 07:55 UTC | |
by kcott (Archbishop) on Jun 07, 2013 at 09:48 UTC |