perlquestion
mndoci
<p>I am trying to do the following</p>
<p>I have some data which looks like
<br>
<code>
1,ABC,X,1.203000e+02
1,ABC,Y,7.830000e+00
2,DEF,X,1.212400e+02
2,DEF,Y,8.810000e+00
3,GHI,X,1.180700e+02
3,GHI,Y,8.550000e+00
5,JKL,X,1.193500e+02
5,JKL,Y,7.270000e+00
.
.
.
</code>
<p>Anyway, I want to use the first column in each line as a unique key for a hash, (e.g. 1,2,3,5 .. and so on). I am doing this as follows</p>
<code>
while (<NEWDATA>){ # where NEWDATA points to a file with the comma delimited data
$currLine = $_; # current, comma-delimited line
chomp $currLine;
@formatDataArray = split(/,/,$currLine); #split at comma
push (@newArray, $formatDataArray[0]); # push first column into newArray
# print OUT "@newArray\n";
}
foreach my $item(@newArray){ # get unique array elements
$seen{$item}++;
}
# numerical sort on keys and add to array
@uniq = sort {$seen{$a} <=> $seen{$b} } keys %seen;
# print to see if things look right
foreach my $element(@uniq){
print OUT "$element\n";
}
</code>
<p>the results of the <code>print</code> command at the end are still random, i.e. not
<code>
1
2
3
5
</code>
</p>
<p>Any ideas. I am sure I am overlooking something very trivial. </p>
<p>mndoci</p>
<p>"What you do in this world is a matter of no consequence. The question is, what can you make people believe that you have done?"-Sherlock Holmes in <i>'A study in scarlet'</i></p>