in reply to Re: Re: extracting values from hashes
in thread extracting values from hashes

If you just want the array elements that exists as keys in the hash, a simple grep() should do the job.
my @array = qw/sarah john/; my %hash = ( sarah => 19, john => 25, emma => 22, ); ## push() would be superfluous my @data = grep exists $hash{$_}, @array; print "data: @data\n"; __output__ data: sarah john

HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Re: Re: extracting values from hashes
by Anonymous Monk on Mar 18, 2003 at 14:30 UTC
    its really the values i wanted, not the keys. thanks though
      Just add a map before the grep like so
      my @data = map $hash{$_}, grep exists $hash{$_}, @array;

      HTH

      _________
      broquaint