elements from array @a that are not in array @b
The more idiomatic way to do this is with a lookup hash. The combination of for/grep is actually two nested loops, meaning that you do a*b comparisons. A hash lookup will be faster for most situations, and clearer to anyone with much Perl experience. To show elements of @a not in @b:
#!/usr/bin/env perl use Modern::Perl; my @a = qw/ foo bar baz /; my @b = qw/ foo bar biz /; my %b = map { $_ => 1 } @b; for (@a){ say unless $b{$_}; }
Aaron B.
Available for small or large Perl jobs; see my home node.
In reply to Re: Default variable within loops
by aaron_baugher
in thread Default variable within loops
by oldwarrior32
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |