Okay, I've been struggling with this all weekend, and I've gotten plenty of help but I'm still not getting it. Here is my code so far: what I want to do is build a few matrices from user input. Eventually I want to multiply them. Another story.
input is as follows
1 2 2 4
4 5 6 6
1 2 2 3
1 2 2 3
sub makeMatrix {
my ($input) = @_;
my @mat;
while (<$input>) {
if ($input eq ""){
print "it's blank\n";
return;
}
else{
push @mat, [ split ];
}
return \@mat;
}
}
my @a = ();
while($a = <>) {
chomp $a;
push @a,($a);
}
@matrices;
push @mat, (makeMatrix(@a));
foreach $input (@matrices){
print "input was $input\n";
}
Why doesn't this work? Why does it not create an array of matrices in @matrices
? Is it the return
statement in the subroutine? My goal is to have two matrices in the matrices array. Thanks for all your help.