Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

nekokak (7400)

nekokak
  (email not shown publicly)
http://d.hatena.ne.jp/nekokak/

Journal of nekokak (7400)

Wednesday November 01, 2006
04:21 AM

list grep

[ #31466 ]

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

more idea?

PS.

http://rafb.net/paste/results/UdqEr958.html
Thanks to hio_d and #catalyst-ja's member.