I want to extract only the value that exists in another array by the value of a certain array.
It cannot be done in List::MoreUtils.
And I wrote such.
package List::Grep; use strict; use warnings; use base 'Exporter'; use vars qw(@EXPORT_OK %EXPORT_TAGS); @EXPORT_OK = qw/list_grep/;
sub list_grep { my $args = shift; my %tmp; @tmp{@{$args->{base}}} = @{$args->{base}}; return wantarray ? @tmp{@{$args->{grep_key}}} : [@tmp{@{$args->{grep_key}}}]; }
1; __END__
=head1 SYNOPSIS
use List::Grep qw/list_grep/; my @hoge = qw/1 2 3 4 5 5/; my @moge = qw/2 5/;
my @result = list_grep({base => \@hoge,grep_key => \@moge});
## 2,5 in @result
=head1 THANKS TO
tokuhirom