> On Monday, April 15, 2002, at 10:32 AM, Raghupathy, Ramesh . wrote: > >> Bob, >> >> You are right about what I wanted to achieve. I was wondering, if I >> could >> do it using just pattern match, without using any control structures like >> (if, while ...), >>
i had to use one loop. sorry. @x=<>; # read in whole file chomp(@x); # remove all newlines at end of each line $x=join "",@x; # collapse into a single string while ($x=~/$word1(.*?)$word2/g) # find text from $word1 to $word - may contain more $word1's within { $z=$1; # because $1 will be changed in substitution of next line $z=~s/.*$word1(.*?)$/$1/; # find text from last occurence of $word to end of line push @y,$z}; # this is the text you want } next you'll tell me you don't want to read the whole file in at once :) that's when you have to do like what i offered the first time. >> Thanks, >> Ramesh >> >> -----Original Message----- >> From: bob ackerman [mailto:[EMAIL PROTECTED]] >> Sent: Friday, April 12, 2002 7:08 PM >> To: [EMAIL PROTECTED] >> Subject: Re: pattern match >> >> >> >> On Friday, April 12, 2002, at 12:58 PM, David Gray wrote: >> >>>> for e.g : >>>> >>>> (not showing the new lines..) >>>> >>>> >>>> ....word1.....word1.....word1....word2....word1...word2....wor >>>> d2....word2.... >>>> ..... >>> >>> You're gonna want to check out (in the perldoc perlre manpage) (??{ code >>> }), which is an example of a recursive regular expression. They have an >>> example that matches nested parenthesis correctly. >>> >>> Cool stuff :) >>> >>> -dave >>> >> but he doesn't want to do nested. as he described he wants text from >> word1 >> to word2 where there is no word1 or word2 in between. then he wants to go >> on to the next pair. >> >> something like this: >> $gotword1 = 0; >> while(<>) >> { >> if ($gotword1) >> # gather text >> while($gotword1 or /$word1/) >> { >> $gotword1=1; >> if (/$word2/ before a $word1) >> { >> #gather last bunch of text and push it to array or >> whatever >> $gotword1=0; >> } >> else >> #gather text >> } >> } >> >> problem with this code is continuing the search from where the last >> search >> ended, >> knowing if you got $word2 before an instance of $word1, >> and gathering the text between. >> >> but it's a start? >> > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]