I am using a range operator in matching #if(or)#ifdef(or)#ifndef to the corresponding #endif directive and remove the code in between them. If I have a nested #if directive my perl code doesn't work.
Here with I am posting a C code snippet
from the current perl code the output is like this{ #if 1 #define done 9 #define do 10 #ifdef #define def1 11 #define thread 12 #endif #define mutex 13 #define inter 14 #endif #define intel 15 #define intel_64 16 }
but actually my output has to be like this{ #define mutex 13 #define inter 14 #endif #define intel 15 #define intel_64 16 }
here is my perl code please help me out in tracking the nested #if using the range operator,{ #define intel 15 #define intel_64 16 }
my ($start, $stop) = (qr '#ifdef|#if|#ifndef|#else', qr '#endif'); open(file1,$file) or die "Error opening input: " . $!; open(file2, ">$filea") or die "Error opening input: " . $!; while (<file1>) { if (/$start/ .. /$stop/) { next; } else { print file2 $_ ; } }
Thanks a lot,
-Prassi
In reply to nested #if directive matching matching by prassi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |