in reply to Re: only increment counter if the ID has not been seen before
in thread only increment counter if the ID has not been seen before
This should output:use warnings; use strict; my $counter = 0; my %hash; while (<DATA>) { my @splits = split; my $snp = $splits[0]; $hash{$snp} ||= ++$counter; print "$hash{$snp} $snp\n"; } __DATA__ foo abc foo cde bar xyz foo hij
... rather than:1 foo 1 foo 2 bar 1 foo
1 foo 1 foo 2 bar 2 foo
|
|---|