note
dvergin
I was going to suggest:
<code>
my @ary2 = grep {defined} @hash{@ary};
</code>
It's tempting to just say <tt>my @ary2 = @hash{@ary}</tt>. But the values in @ary that don't match keys in %hash produce undefined values that have to be weeded out.
<p />
Here's a quick demo:
<code>
#!/usr/bin/perl -w
use strict;
my @ary = ('a', 'c', 'g', 'l');
my %hash = (a => 1, b => 2, c => 3, d => 4);
my @ary2 = grep {defined} @hash{@ary};
print "[$_]\n" for @ary2;
</code>
270807
270818