replicant4 has asked for the wisdom of the Perl Monks concerning the following question:
What I need is that every time that compare one $site from @array1, I need to reset the counters to 0 if it is possible. Then I need to add the values of the counters. Is this possible? Thanks in advance for anyone's helpuse strict; use warnings; use Algorithm::Loops qw( MapCar ); my @site1 = qw( AATKKM 123456 ); my @site2 = qw( GGGGGG !@#$%^ ); my $site1; my $site2; my @pairs; my %counts; foreach $site1 (@site1) { my @site1_parts = split(//, $site1); foreach $site2 (@site2) { my @site2_parts = split(//, $site2); MapCar { $counts{$_[0].$_[1]}++ } \@site1_parts, \@site2_parts; } } print($_, ': ', $counts{$_}, $/) foreach (sort keys %counts); __END__ output ====== 1!: 1 1G: 1 2@: 1 2G: 1 3#: 1 3G: 1 4$: 1 4G: 1 5%: 1 5G: 1 6G: 1 6^: 1 A!: 1 A@: 1 AG: 2 K$: 1 K%: 1 KG: 2 MG: 1 M^: 1 T#: 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: a bit more help with pairwise comparisons between strings in arrays.
by ikegami (Patriarch) on Oct 20, 2004 at 18:28 UTC | |
by replicant4 (Novice) on Oct 20, 2004 at 21:01 UTC | |
by ikegami (Patriarch) on Oct 20, 2004 at 21:10 UTC | |
by replicant4 (Novice) on Oct 21, 2004 at 15:39 UTC | |
by ikegami (Patriarch) on Oct 21, 2004 at 16:58 UTC |