in reply to Re: exclude all members of @a from @b
in thread exclude all members of @a from @b
I'd go one step further and make a hash of the contents of @$b for lookup purposes. It's faster to look up values in a hash than in an array.
sub exclude { my ($a, $b) = @_; my %lookup = map { $_ => undef } @$b; for (1..@$a) { my $i = shift @$a; push(@$a, $i) unless exists $lookup{$i}; } @$a; }
|
|---|