Hash to the rescue.
However, some 3 letter words occur more than onces, it shows correctly!#!/usr/bin/perl use warnings; use strict; my $a="NTCA TCC TCGTCTTTCTTTTTATTGTACTATTAATAGTGCTGTTGATGGCTACTCCTGCTT +CCACAT CAACAGCGACGCCGGCGTATAATCATTATGACAACCACGACTAACAATAAAAAGAGCAGTAGAAGGCCCC +CGC CTCACGTAGTCGTGGTTGCAGCCGCGGCTGACGATGAAGAGGGAGGCGGGGGT N"; $a=~s/\s+?//g; my %has_dat; foreach my $alpha(split//,$a){ $has_dat{$alpha}++ if $alpha eq ('A'|'T'|'G'|'C') or $alpha ne + ('A'|'T'|'G'|'C'); } print $_,'=',$has_dat{$_},' ' for keys %has_dat; print "\nLength: ",length($a),$/; %has_dat=(); while($a=~m/\G(\w{3})/gc){ $has_dat{$1}++; } my $counter=0; foreach (sort keys %has_dat){ if($counter==5){print "\n";$counter=0;} print $_,'=',$has_dat{$_},' ';++$counter; }
In reply to Re: How can I get correct result in counting 3-letter words?
by 2teez
in thread How can I get correct result in counting 3-letter words?
by supriyoch_2008
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |