Kent, Mr. John (Contractor) wrote:
...
> my(@ACTIVE) = qw {gid240 gid278 gid301};
> my(@LOGGED) = qw {gid306 gid240 gid278 gid301};
>
> # This doesn't work, finds a match for every item in
> # LOGGED, seems to be matching on "gid" but ignoring the number
> foreach (@LOGGED){
> unless (grep /$_/,@ACTIVE){
> print "No Match for $__\n" if ($DEBUG == 1);
> #do something here with what didn't match";
> } else {
> print "found $_ in ACTIVES\n" if ($DEBUG == 1);
> }
> }
Others have explained the localization of $_ issue. It's not important for
such a small data set, but if @ACTIVE is large, you can improve performance
by doing a hash lookup instead of a grep():
use strict;
my(@ACTIVE) = qw {gid240 gid278 gid301};
my(@LOGGED) = qw {gid306 gid240 gid278 gid301};
my %h; @[EMAIL PROTECTED] = ();
print exists $h{$_} ? "Found" : "No match for", " $_\n" for @LOGGED;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>