in reply to stripping an array

my @arr1 = qw(2 4 5); my @arr2 = ('1,nfs', '2,afp', '3,cifs', '4,dns', '5,backup'); my %arr1_as_hash; $arr1_as_hash{$_}++ for @arr1; my @arr3 = map { my ($key, $val) = split /,/; $arr1_as_hash{$key} ? $val : (); } @arr2;

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: •Re: stripping an array
by jdporter (Paladin) on Jan 02, 2003 at 18:33 UTC
    For variety, here's a solution that uses a kind of Schwartzian Transform (but grepping instead of sorting).
    my %arr1_as_hash; @arr1_as_hash{@arr1} = (); my @arr3 = map { $_->[1] } grep { exists $arr1_as_hash{$_->[0]} } map { [ split /,/ ] } @arr2;

    jdporter
    The 6th Rule of Perl Club is -- There is no Rule #6.