in reply to hashes - finding values
This isn't terrifically optimal so you may want to create another hash where the values are the keys (although the solution starts to look like finding an array intersection which is another option).my @array = qw/ foo bar baz quux /; my %hash = qw/ f1 baz f2 foo /; my @newarray; foreach my $thing (@array) { push @newarray, $thing if grep { $_ eq $thing } values %hash; } print "newarray - @newarray\n"; __output__ newarray - foo baz
_________
broquaint
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: hashes - finding values
by Anonymous Monk on Jul 03, 2003 at 13:45 UTC | |
by broquaint (Abbot) on Jul 03, 2003 at 13:50 UTC |