Perl regular exp

2006-04-11 Thread Sonika Sachdeva
Hi , print $line if ($line =~ /pattern1 && pattern2 && pattern3/); works .. but my $regex="$pattern1 && $pattern2 && $pattern3"; print $line if ($line =~ /$regex/); doesn't work... Any clues ? Thanks,

Re: Perl regular exp

2006-04-11 Thread Oliver Block
Am Mittwoch, 12. April 2006 00:38 schrieb Sonika Sachdeva: > my $regex="$pattern1 && $pattern2 && $pattern3"; > print $line if ($line =~ /$regex/); > > doesn't work... Why should it work? regards, Oliver -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PRO

Re: Perl regular exp

2006-04-11 Thread Sonika Sachdeva
How do I use variable string value as a regular expression? On 4/11/06, Oliver Block <[EMAIL PROTECTED]> wrote: > > Am Mittwoch, 12. April 2006 00:38 schrieb Sonika Sachdeva: > > my $regex="$pattern1 && $pattern2 && $pattern3"; > > print $line if ($line =~ /$regex/); > > > > doesn't work... > Why

Re: Perl regular exp

2006-04-11 Thread Peter Cornelius
What do you mean by 'works'? It looks to me like this will print the line if the string 'pattern1 && pattern2 && pattern3' is in the line. Not if pattern1 is in the line and pattern2 is in the line and pattern3 is in the line. Is that what you mean? I think some more detail would help me

RE: Perl regular exp

2006-04-11 Thread Ankur Gupta
Sonika Sachdeva scribbled on Tuesday, April 11, 2006 3:39 PM: > Hi , Please state your problem statement. What are you trying to achieve with this program. add use strict; use warnings; at the top of your perl program and then try to run. > print $line if ($line

Re: Perl regular exp

2006-04-11 Thread Oliver Block
Am Mittwoch, 12. April 2006 01:02 schrieb Sonika Sachdeva: > How do I use variable string value as a regular expression? print $line if $line =~ /$pattern/; regards, oliver -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: Perl regular exp

2006-04-11 Thread Peter Cornelius
This matches: my $test_string = 'This is my test string'; my $pattern1 = 'This is'; print "Passed test 1 $/" if ($test_string =~ /$pattern1/); I think that at least part of your problem is the '&&' characters. I'm guessing that you don't mean to match a literal '&&' but that is what your

Re: Perl regular exp

2006-04-11 Thread Sonika Sachdeva
$str1=shift; $str2=shift; $str3=shift; my $querystring="$str1 && $str2 && $str3"; foreach (@LINES){ push @output,$_ if /$querystring/ ; } does not work even if I have @LINES containing all 3 words. Thanx, On 4/11/06, Peter Cornelius <[EMAIL PROTECTED]> wrote: > > What do you me

Re: Perl regular exp

2006-04-11 Thread Sonika Sachdeva
words to match are variable e.g array @words On 4/11/06, Sonika Sachdeva <[EMAIL PROTECTED]> wrote: > > $str1=shift; > $str2=shift; > $str3=shift; > > my $querystring="$str1 && $str2 && $str3"; > > foreach (@LINES){ > push @output,$_ if /$querystring/ ; > } > > does not work even i

Re: Perl regular exp

2006-04-11 Thread Oliver Block
Am Mittwoch, 12. April 2006 01:15 schrieb Sonika Sachdeva: > $str1=shift; > $str2=shift; > $str3=shift; > > > foreach (@LINES){ > push @output,$_ if /$querystring/ ; > } > > does not work even if I have @LINES containing all 3 words. .. pursh @output, $_ if(/$str1/ && /$str2/ && /$s

RE: Perl regular exp

2006-04-11 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Sonika Sachdeva wrote: > $str1=shift; > $str2=shift; > $str3=shift; > > my $querystring="$str1 && $str2 && $str3"; > > foreach (@LINES){ > push @output,$_ if /$querystring/ ; > } > Correct because unless you have abc && efg && hij in the $_ it will not work because that

Re: Perl regular exp

2006-04-11 Thread Peter Cornelius
But I'll bet you don't have @LINES containing all 3 words separated by 2 '&' symbols. You need to break this up into: if($line =~ /$pattern1/ && $line =~ /$pattern2/) { ... } or something similar. On Apr 11, 2006, at 4:15 PM, Sonika Sachdeva wrote: my $querystring="$str1 && $str2 && $str

Re: Perl regular exp

2006-04-11 Thread Sonika Sachdeva
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? On 4/11/06, Wagner, David --- Senior Programmer Analyst --- WGO < [EMAIL PROTECTED]> wr

Re: Perl regular exp

2006-04-11 Thread Oliver Block
Am Mittwoch, 12. April 2006 01:27 schrieb Sonika Sachdeva: > 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? /abc|def|ghi/ matc

RE: Perl regular exp

2006-04-11 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Analyst --- WGO Cc: Peter Cornelius; beginners@perl.org Subject: Re: Perl regular exp 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?

RE: Perl regular exp

2006-04-11 Thread Ankur Gupta
Sonika Sachdeva 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

Re: Perl regular exp

2006-04-11 Thread Dr.Ruud
Oliver Block schreef: > Sonika Sachdeva: >> How do I use variable string value as a regular expression? > > print $line if $line =~ /$pattern/; Often you want to have special characters quoted: /\Q$pattern\E/ and print for $line; See also qr// in perlop. -- Affijn, Ruud "Gewoon is een t

Re: Perl regular exp

2006-04-12 Thread Randal L. Schwartz
> ""Sonika" == "Sonika Sachdeva" <[EMAIL PROTECTED]> writes: "Sonika> Hi , "Sonika> print $line if ($line =~ /pattern1 && pattern2 && pattern3/); "Sonika> works .. but For what meaning of "works"? If you want to find the string "pattern1 && pattern2 && pattern3", I guess. That's been prett

Re: Perl regular exp

2006-04-12 Thread Randal L. Schwartz
> ""Ankur" == "Ankur Gupta" <[EMAIL PROTECTED]> writes: "Ankur> Sonika Sachdeva scribbled on Tuesday, "Ankur> 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

Re: Perl regular exp

2006-04-12 Thread Sonika Sachdeva
Thanks all. On 12 Apr 2006 06:23:53 -0700, Randal L. Schwartz wrote: > > > ""Ankur" == "Ankur Gupta" <[EMAIL PROTECTED]> writes: > > "Ankur> Sonika Sachdeva scribbled on > Tuesday, > "Ankur> April 11, 2006 4:27 PM: > > >> Actually I am looking for AND and OR combin

Re: Perl regular exp

2006-04-12 Thread Randal L. Schwartz
> "Sonika" == Sonika Sachdeva <[EMAIL PROTECTED]> writes: >> You could instead keep in mind that: >> >> /^(?=.*foo)(?=.*bar)/ Ooops. that should be (?=.*?foo) for efficiency. >> my $regex = "^" . join "", map "(?=.*\Q$_\E)", @words; change .* to .*? there. -- Randal L. Schwartz - Stoneh