Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
This works fine and gets it right, but I also want the patterns that do not occur to be entered into the hash with a value of 0. I've tried to add the following code but it seems to mess up the counts of the matched patterns:The arrays contain data similar to this: @truncated_sequences = qw(JFADLKGJLFLGJGAFDJ DSJLJFLDJSLF...E.T.C); @triamino_combo = qw(AAA AAB AAC AAD.......e.t.c); foreach $prot_string (@truncated_sequences) { foreach $tri_seq (@triamino_combo) { while ($prot_string =~ /$tri_seq/g) { $tri_freq{$tri_seq}++; } } }
Any help would be appreciated, thanksforeach $prot_string (@truncated_sequences) { foreach $tri_seq (@triamino_combo) { if ($prot_string =~ /$tri_seq/g) { $tri_freq{$tri_seq}++; } else { $tri_freq{$tri_seq} = "0"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: manipulating hashes
by thelenm (Vicar) on Nov 19, 2002 at 19:14 UTC | |
by insensate (Hermit) on Nov 19, 2002 at 19:23 UTC | |
|
Re: manipulating hashes
by Thelonius (Priest) on Nov 19, 2002 at 19:31 UTC | |
|
Re: manipulating hashes
by John M. Dlugosz (Monsignor) on Nov 19, 2002 at 19:26 UTC |