Here's a small self-contained files to demonstrate the basics. Edit to suit :-)
Data::Dumper
helps with visualizing data structures - a great learning tool.
The []
acts as an "anonymous array constructor". You can read more about that with perldoc perlref
(or follow the previous link). Sometimes you have to explain something to someone else before you can be even somewhat sure you understand it yourself, so bear with me ;-)
use 5.10.0 ;
use Data::Dump;
use strict;
use warnings;
my @AoA ;
#my $file = "testdata.txt";
#open my ($fh), "<", "$file" or die "$!";
#while (<$fh>) {
while (<DATA>) {
my @line = split ;
push @AoA, [@line] ;
}
say for @AoA; # shows array references
say @{$AoA[0]}[0] ; # dereference an inner element
foreach my $i (0..$#AoA)
{
say "@{$AoA[$i]}[2..4]" ; # prints columns 3-5
}
dd (@AoA) ; # dump the data structure we created ... just to look at it.
__DATA__
1 2 3 0 8 8
4 5 6 0 7 8
7 8 9 0 6 7