in reply to Re: hashes - finding values
in thread hashes - finding values

Thanks broquaint but I want to push the corresponding keys to the matching values into the new array. I think your code keeps values in the array that are present in the hash.
my @array = qw/ f1 f2 f3 f4/; my %hash = qw/ f1 foo f2 bar/; #OUTPUT # newarray - foo bar.
I'm not too sure how to adapt your code to do this!

Replies are listed 'Best First'.
Re: Re: Re: hashes - finding values
by broquaint (Abbot) on Jul 03, 2003 at 13:50 UTC
    Ok, then you'll want something like ...
    my @array = qw/ foo bar baz quux /; my %hash = qw/ f1 baz f2 foo /; my @newarray; for my $k (keys %hash) { push @newarray, $k if grep { $hash{$k} eq $_ } @array; } print "newarray - @newarray\n"; __output__ newarray - f1 f2

    HTH

    _________
    broquaint