http://www.perlmonks.org?node_id=1007921


in reply to What is wrong in this code???

A much shorter solution (probably slower) uses a regexp to copy all the A's to a temp array and then uses the size of that array as the count. Repeat for other letters.

use strict; use warnings; use Data::Dumper qw(Dumper); my @letters = ('A', 'T', 'G', 'C', '-'); while (my $seq = <>){ print $seq; my @temp; my %cnts = map {($_, scalar ( @temp = $seq =~ /($_)/g))} @letters; print Dumper \%cnts; }
Bill