Sonika Sachdeva <mailto:[EMAIL PROTECTED]> scribbled on Tuesday,
April 11, 2006 4:27 PM:
> Actually I am looking for AND and OR combinations..and the number of
> words are not fixed.
> ie @words is the variable and I need to have OR and AND combinations
> of @words. to match in LINES How do I go about it?
perldoc -f eval
eg.
use strict;
use warnings;
## number of @words can vary
my @words = qw/a b c d/;
## $condition can be ||, and, or.
my $condition = '&&';
my $string = join " $condition ", map { "/$_/" } @words;
$string = 'print $_ if ' . $string;
# $string will have 'print $_ if /a/ && /b/ && /c/ && /d/'
while (<>){
eval $string;
}
But make sure that @words and $condition are not input by user as then
it creates a security hole.
Or if they are input by the user, then check for the values before you
create the eval string.
--Ankur
perl -e '[EMAIL PROTECTED]/(&^\+_'
Warning: Use of comic-book profanity not allowed.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>