Rob,
 
   The input file you described is not correct, since
it has  
#ifdef def2
statement3;
#else
statement4;
#endif
nested within another #ifdef ... #else ... #endif.
 
 My input file is the output of 
"diff -D def file1 file2" (on unix). This will
generate a file which has the following patterns and
none of the patterns can be nested within the other:

#ifdef .... #else ... #endif
#ifndef .... #else ... #endif
#ifdef .... #endif
#ifndef .... #endif

   I need to substitute the above patterns to be read
by a home grown program. 
 
   I encountered a problem due to the following
reason.
There was:

#ifndef def .... #endif def    -  Call it sentence1
#ifndef def ... #else def ... #endif def   - Call it
sentence2

   I tried the following line but it matched sentence1
and sentence2 together. I need to match sentence1 and
sentence2 seperately. 
$line1 =~ 
m/#ifndef\s+def(.*?)#else\s+def(.*?)#endif\s+def/isg  

For this 
#ifndef def (...1...) #else def (...2...) #endif def  

should be matched only if #if is not there within 
(...1...) and (...2...).

  Hopefully I have conveyed it more clearly.

Thanks,
Raghu



======================================================
Raghupathy wrote:
> Hi All,
>
>   I have a text file as shown below. How do I match
> patterns like the following:
>
> Pattern to be matched:
> =========================
> #ifndef def
> ......   (anything except #if)
> #else def
> .......  (anything except #if)
> #endif def
>
>
> My Input Data:
>
=====================================================
> #ifndef def
> DELETE sys1..tbl1
> #endif def
>
> SELECT col1, col2, col3
> #ifndef def
>    FROM    sys1..tbl1
> #else def
>    FROM    sys1..tbl2
> #endif def
> WHERE  schdid is not null
>
>
=====================================================
>
> What I tried is below (but did not work since it
> captured patterns which had "#if" nested within the
> main pattern).
>
> $line1 =~
> m/#ifndef\s+def(.*?)#else\s+def(.*?)#endif\s+def/isg
>

I thought I knew what you meant, but then I changed my
mind!

If your input file is, say

statement1;
#ifdef def1
statement2;
#ifdef def2
statement3;
#else
statement4;
#endif
statement5;
#else
statement6;
#ifdef def3
statement7;
#else
statement8;
#endif
statement9;
#endif

What is it that you want to capture?

Rob


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to