Hi All
I have a problem in grouping rows and creating a vector.
A,180,12.345
A,365,67.890
B,10950,78.987
B,1095,67.123
In my sample file, the first column is the ID, the second column the date in days and the final column is a value. For rows with the same ID, I need to group them and create a vector with the dates, their corresponding value and the sequence they should get loaded into the system. So the resultant output will look something like this.
BAS,A
ro,180,12.345,1
ro,365,67.890,2
BAS,B
ro,1095,67.123,1
ro,10950,78.987,2
I've tried to hack together something but my feeling is that its way off as I'm not that familiar with hashes which I've been advised is the way to go here.
if (exists $sh_ids->{$id}) { sh_ids->{$id}++}
else {sh_ids->{$id} = 0}
foreach $key(sort keys %{$sh_ids})
{
print OUTFILE "BAS,$id\n";
for ($i=0; $i < $sh_ids->{$key}; $i++ $seq++)
{
print OUTFILE "ro,$date,$value,$seq\n";
}
}
As always, any help would be appreciated.
TIA..