in reply to exclude all members of @a from @b

First, most likely, you wouldn't be passing in a single array; most people in this case would use refernces to pass the arrays in and forget about having to worry about where one ends and the other begins.

Additionally, there's no reason to invoke a regex here when a simple neq would do the job. Something like this would be better:

sub exclude { my ($a, $b) = @_; for (1..@$a) { my $i = shift @$a; push @$a, $i if ( !grep { $_ eq $i } @$b ); } @$a; }
Of course, with perl, TIMTOWTDI...
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Replies are listed 'Best First'.
Re: Re: exclude all members of @a from @b
by tomhukins (Curate) on May 13, 2001 at 17:53 UTC

    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; }