Skip Menu |

This queue is for tickets about the List-MoreUtils CPAN distribution.

Report information
The Basics
Id: 70678
Status: open
Priority: 0/
Queue: List-MoreUtils

People
Owner: Nobody in particular
Requestors: BitCard [...] ResonatorSoft.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.33
Fixed in: (no value)



Subject: [PATCH] foundin, notin functions
# Find items in @B that are in @A sub foundin (\@\@) { my ($A, $B) = @_; return grep { my $i = $_; any { $i eq $_ } @$A; } @$B; } # Find items in @B that are not in @A sub notin (\@\@) { my ($A, $B) = @_; return grep { my $i = $_; none { $i eq $_ } @$A; } @$B; } Not sure if there are some better optimizations for these, but that's about as far as I can see. The XS part will need to be filled in, too.
Next List::MoreUtils (0.420) will come with a listcmp which provides following: my @a = qw(Hello World); my @b = qw(Hello Dave); my $c = listcmp @a, @b; say Dumper $c; # { Dave => [1], Hello => [0, 1], World => [0] } Relying on that, you can implement foundin: sub foundin { my $A, $B = @_; my $c = listcmp @$A, @$B; return grep { scalar @{$c->{$_}} == 2 } keys %$c; } I think I wait providing such a function until I get a bit more response (avoiding unfortunate names when more feedback is coming in ...).