in reply to matching arrays
Note that I did switch your hashes for arrays, as it made more sense to me to have them this way.use strict; use warnings; my @occurances = ( [ 'male' ], [ 'male' ], [ 'male', 'child' ], [ 'female' ], [ 'child', 'female' ], [ 'female', 'child' ], [ 'female', 'male', 'child' ], ); my @terms = ( [ 'male' ], [ 'female' ], [ 'child' ], [ 'male', 'female' ], [ 'male', 'child' ], [ 'female', 'child' ], [ 'male', 'female', 'child' ], ); my %tally; foreach my $array_ref ( @occurances ) { $tally{stringify(@$array_ref)}++; } foreach my $array_ref ( @terms ) { if ( defined $tally{stringify(@$array_ref)}) { print "Terms:" . join (" and ", @$array_ref) . " were found " . $tally{stringify(@$array_ref)} . " times\n" } else { print "Terms:" . join (" and ", @$array_ref) . " were found 0 times\n" } } sub stringify { join ("+", sort {$b cmp $a} @_) }
-enlil
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: matching arrays
by rsiedl (Friar) on May 25, 2004 at 21:41 UTC | |
|
Re: Re: matching arrays
by rsiedl (Friar) on May 25, 2004 at 22:19 UTC |