Subj : Re: any function to handle this kind of counting? To : comp.programming From : Rob Thorpe Date : Thu Aug 04 2005 03:44 am John W. Krahn wrote: > Rob Thorpe wrote: > > Peter Ammon wrote: > >>Just wait 'til the Perl guy gets here, though! > > > > I can take on that mantle: > > > > for(0..($#a<$#b?$#a:$#b)){++$ans{$b[$_]}{$a[$_]};} > > Way too much punctuation and not enough whitespace. :-) > > ++$ans{ $b[ $_ ], $a[ $_ ] } for 0 .. ( @a < @b ? $#a : $#b ); I know, I was being facetious :) > You don't really need a hash of hashes as perl will concatenate comma > separated values in the hash key. > > $ perl -e' > @a = qw/ a b a e a /; > @b = qw/ 1 2 1 4 5 /; > $; = ""; # change the subscript separator > ++$ans{ $b[ $_ ], $a[ $_ ] } for 0 .. ( @a < @b ? $#a : $#b ); > print "$_\t$ans{$_}\n" for sort keys %ans; > ' > 1a 2 > 2b 1 > 4e 1 > 5a 1 I was making a data-structure the same as Jon's hash-of-hashes. The data structure you mention could be used. But if it was then AFAIK using "keys" to go through it later might not be so easy. .