Hi,
I am new to this site and in the process of teaching myself
perl. I have a question that I hope someone can answer.
I am playing about with a small script that uses a 2D array,
I think its called an annonymous array( feel free to correct
me, if I'm wrong ). The array is 'coded' into the script but I would like to fill it from a data file.
My array is like this...........
my @picks;
@picks = (
[ 2, 6, 9, 16, 18, 28 ],
[ 2, 11, 16, 18, 28, 29 ],
[ 11, 18, 20, 21, 25, 28 ],
[ 10, 11, 13, 17, 28, 34 ]
);
the script works fine because I can do the following...
for my $p ( 0 .. $#picks ) {
my @set = @{$picks[ $p ]};
if ( grep /^$n$/, @set ) {
#dosomething;
}
}
My question is: How would I read in the elements into @picks
from a data file, without having to edit further code.
I have tried something like this, but to no avail...
$filename = "data.txt";
my @picks;
open(DAT, "<$filename" or die("Could not open file!"
@picks=<DAT>;
close(DAT);
where "data.txt" loks like this ......
1 2 5 7 9 11
12 13 17 27 33
1 23 24 29 37 42
Please, this is not homework or the likes, I AM trying to
teach myself.
Thanks
I am new to this site and in the process of teaching myself
perl. I have a question that I hope someone can answer.
I am playing about with a small script that uses a 2D array,
I think its called an annonymous array( feel free to correct
me, if I'm wrong ). The array is 'coded' into the script but I would like to fill it from a data file.
My array is like this...........
my @picks;
@picks = (
[ 2, 6, 9, 16, 18, 28 ],
[ 2, 11, 16, 18, 28, 29 ],
[ 11, 18, 20, 21, 25, 28 ],
[ 10, 11, 13, 17, 28, 34 ]
);
the script works fine because I can do the following...
for my $p ( 0 .. $#picks ) {
my @set = @{$picks[ $p ]};
if ( grep /^$n$/, @set ) {
#dosomething;
}
}
My question is: How would I read in the elements into @picks
from a data file, without having to edit further code.
I have tried something like this, but to no avail...
$filename = "data.txt";
my @picks;
open(DAT, "<$filename" or die("Could not open file!"
@picks=<DAT>;
close(DAT);
where "data.txt" loks like this ......
1 2 5 7 9 11
12 13 17 27 33
1 23 24 29 37 42
Please, this is not homework or the likes, I AM trying to
teach myself.
Thanks