my @colours = qw/red green yellow orange white mauve blue ochre pink purple gold silver grey brown steel/; my @find = qw/red blue green black/; my %colours; @colours{@colours} = @colours; my @found = grep { defined } @colours{@find}; print join( ', ', @found );
This prints "red, blue, green". Adapted from a Perl.sig Perl Tip on slicing arrays and hashes.
No comments:
Post a Comment