I am currently trying to pass a 32 by 48 matrix file to a multi-dimensional array in Perl. I am able to access all of the values, but I am having issues accessing a specific value.
Here is a link to the data set:
http://paste-it.net/public/x1d5301/
Here is what I have for code right now.
#!/usr/bin/perl
open FILE, "testset.txt" or die $!;
my @lines = <FILE>;
my $size = scalar @lines;
my @matrix = (1 .. 32);
my $i = 0;
my $j = 0;
my @micro;
foreach ($matrix)
{
foreach ($lines)
{
push @{$micro[$matrix]}, $lines;
}
}
It doesn’t seem you understand that
$matrixonly indicates@matrixwhen it is immediately followed by an array indexer:[ $slot ]. Otherwise,$matrixis a completely different variable from@matrix(and both different from%matrixas well). See perldata.Don’t! use English–that way!
This brings in
$MATCH,$PREMATCH, and$POSTMATCHand incurs the dreaded$&, $`,$'penalty. You should wait until you’re using an English variable and then just import that.Two things: 1) use lexical file handles, and 2) use the three-argument
open.As long as I’m picking: Don’t slurp big files. (Not the case here, but it’s a good warning.)
I see we’re at the "PROFIT!!" stage here…
You don’t have a variable
$matrix; you have a variable@matrix.The same thing is true with
$lines.Rewrite: