benwilkinson
asked on
@data
I need to fill @data with information in the following format:
@data =([date1,date2,date3,date4 ],[1,2,3,4 ],[10,20,3 0,40]);
using a text file which is formatted as follows:
date1,1,10
date2,2,20
date3,3,30
date4,4,40
@data =([date1,date2,date3,date4
using a text file which is formatted as follows:
date1,1,10
date2,2,20
date3,3,30
date4,4,40
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The difference between my answer and lambda's is that my method will create a multidimensional array (an array of references to arrays) whereas lambda's will make a single array with all the data for the first field, followed by all the data for the second field, etc. If you wanted a single dimension array, use lambda's code instead of mine.
ASKER
Thanks - actually found the @data(\@1,\@2,\@3) technique seconds before the reply appeared.
Works perfectly for my needs
thnks again
Works perfectly for my needs
thnks again
ASKER
Thanks - actually found the @data(\@1,\@2,\@3) technique seconds before the reply appeared.
Works perfectly for my needs
thnks again
Works perfectly for my needs
thnks again
mattrope :
If I had seen ur soln, I wouldn't have posted my own. Actually I saw it only after I did.
:-))
If I had seen ur soln, I wouldn't have posted my own. Actually I saw it only after I did.
:-))
while( <F> ){
chomp;
my $n = 0;
for( split/,/ ){ push @{$data[$n++]},$_ }
}
chomp;
my $n = 0;
for( split/,/ ){ push @{$data[$n++]},$_ }
}
open (FILE, "Data.txt"); # path to text file.
@File = <FILE>;
close (FILE);
foreach $line (@File)
{
($first, $second, $third) = split (/,/, $line);
push (@arrFirst, $first);
push (@arrSecond, $second);
push (@arrThird, $third);
}
@data = (@arrFirst, @arrSecond, @arrThird);