I have a script that works fine when the data is stored in the same file as the script.
The data is a 2-D array.
because the file is quite large, I stored it in a seperate .txt file to read only from the script.
But the script does not 'see' the data as a 2-d array, as it can't access specific elements.
I have scaled it down to show you what I mean:
Here data in ray.txt
[1,10,100,"a",5,2],
[2,10,100,"b",5,2],
[3,10,100,"c",5,2],
[4,10,100,"d",5,2],
[5,10,100,"e",5,2],
Here is the Script that reads from it:
$TMP='c:/scripts/ray.txt';
open (FILE,$TMP) | | die "cannot open file for read";
while (<FILE> )
{
push(@RAY,$_);}
close FILE;
#test if array has been created.
print "@RAY\n"; #prints OK
$num=scalar(@RAY); #returns 5
print "$num\n";
$row=($RAY[1]->[3]);#does not work
print "$row\n";
my $var=($RAY[1]->[2]);#does not work
print "$var\n";
The exact script works OK if the data is in the same file as the script, once the data is read, the script should work as normal??right?
Sher
The data is a 2-D array.
because the file is quite large, I stored it in a seperate .txt file to read only from the script.
But the script does not 'see' the data as a 2-d array, as it can't access specific elements.
I have scaled it down to show you what I mean:
Here data in ray.txt
[1,10,100,"a",5,2],
[2,10,100,"b",5,2],
[3,10,100,"c",5,2],
[4,10,100,"d",5,2],
[5,10,100,"e",5,2],
Here is the Script that reads from it:
$TMP='c:/scripts/ray.txt';
open (FILE,$TMP) | | die "cannot open file for read";
while (<FILE> )
{
push(@RAY,$_);}
close FILE;
#test if array has been created.
print "@RAY\n"; #prints OK
$num=scalar(@RAY); #returns 5
print "$num\n";
$row=($RAY[1]->[3]);#does not work
print "$row\n";
my $var=($RAY[1]->[2]);#does not work
print "$var\n";
The exact script works OK if the data is in the same file as the script, once the data is read, the script should work as normal??right?
Sher