Mahurshi Akilla wrote:
I am trying to read a csv file into a 2D array matrix
I am having a hard time trying to get the array returned by split
function to "attach" to a 2D array.
See the code below for further info on what I'm trying to do ....
## initialize
$row = 0;
$col = 0;
## go thru each line of file
while (<STDIN>) {
## need to correct below line to append array returned by split to
$matrix[$row][ ....]
$matrix[$row] = split (/,/, $_);
##
## more code
##
$row = $row + 1;
}
## need the above so i can do something like below
print $matrix[1][1];
Is there a way to do this?
Yes, you need to create an anonymous array to hold it.
$matrix[$row] = [ split (/,/, $_) ];
See:
perldoc perldsc
perldoc perllol
--
Just my 0.00000002 million dollars worth,
Shawn
"For the things we have to learn before we can do them, we learn by doing them."
Aristotle
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/