how do i assign a list of data from text file to array value, row and column number in perl
I have the list below in a text file
0,0,apple
0,1,dog
0,2,chicken
1,0,elephant
1,1,cow
1,2,tiger
I would like my @arr to be
$arr[0][0] = apple
$arr[0][1] = dog
$arr[0][2] = chicken
$arr[1][0] = elephant
$arr[1][1] = cow
$arr[1][2] = tiger
first number to be row, second number to be column, third to be the array value
I'm not going to give you the code, as you haven't demonstrated that you've made any effort to work out how to do this. But here are some clues.
- Open a file and link it with a filehandle using
open()
- Read data from a filehandle using I/O operators
- Remove the newline from a record using
chomp()
- Split a record into fields using
split()
- Learn about two-dimensional arrays in perldoc perllol