I don't think I understand this. per perldoc and your instruction this should work.
my @exclude = qw /du huh . ../; %exclude = map {$_=>1} @exculde; print "$_\n" foreach (@exclude); # Prints array print "$k $v\n" while (($k,$v) = each %exclude); #prints nothing. Paul > -----Original Message----- > From: Bob Showalter [mailto:[EMAIL PROTECTED]] > Sent: Friday, December 13, 2002 10:44 AM > To: 'Paul Kraus'; 'Perl' > Subject: RE: Conditional Array lookup > > > > -----Original Message----- > > From: Paul Kraus [mailto:[EMAIL PROTECTED]] > > Sent: Friday, December 13, 2002 10:19 AM > > To: 'Perl' > > Subject: Conditional Array lookup > > > > > > Is there a way to do an if or unless against an entire array. > > > > @exclude = .... > > > > #compare $soomevaraible to every element of @exclude. > > unless ($somevariable eq @exclude){ > > ... > > } > > The FAQ addresses this: > > perldoc -q 'How can I tell whether a list or array > contains a certain element?' > > From your example, it sounds like @exclude is a list of > things you want to test against repeatedly. If so, turn > @exclude into a hash: > > %exclude = map { $_=>1 } @exclude; > > Now you can test quickly: > > unless (exists $exclude{$somevar}) { > print "$somevar is OK\n"; > } > > If you only need to check once, grep() is ok: > > unless (grep { $_ eq $somevar } @exclude) { > print "$somevar is OK\n"; > } > > But don't do that repeatedly; use the hash instead. > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]