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
Download (untitled) / with headers
text/plain 419b
# 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.
Download (untitled) / with headers
text/plain 517b
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 ...).


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.