I know this is a fairly simple question, but I cannot figure out how to store all of the values in my array the way I want to. Here is a small portion what the .txt file looks like:
0 A R N D
A 2 -2 0 0
R -2 6 0 -1
N 0 0 2 2
D 0 -1 2 4
Each value is delimited by either two spaces - if the next value is positive - or a space and a '-' - if the next value is negative
Here is the code:
use strict;
use warnings;
open my $infile, '<', 'PAM250.txt' or die $!;
my $line;
my @array;
while($line = <$infile>)
{
$line =~ /^$/ and die "Blank line detected at $.\n";
$line =~ /^#/ and next; #skips the commented lines at the beginning
@array = $line;
print "@array"; #Prints the array after each line is read
};
print "\n\n@array"; #only prints the last line of the array ?
I understand that @array only holds the last line that was passed to it. Is there a way where I can get @array to hold all of the lines?