V
Vittal
Hello All,
I am trying to write a perl script which removes the contents between
two plain double quotes. (I am parsing C and C++ files.) What I mean
by plain is, double quote (") should not have been preceeded by single
quote (') or back slash(\).
For this I wrote the following code, which is serving the purpose but
partially.
*******************************************************************************
#!/usr/bin/perl
open FILE , "./y.c";
while (<FILE>)
{
$temp .= $_;
}
$temp1 = $temp;
while ($temp && $temp =~ /[^'\\]("([^"])*")/s)
{
$find = $1;
$temp = $';
if (!($2 =~ /['\\]/)){
$temp1 =~ s/\Q$find//;
}
}
print $temp1;
******************************************************************************
So if I have a .c file like this:
******************************************************************************
#include <stdio.h>
int main ()
{
char c = '"';
printf("I should be removed \n");
printf ("Testing under proggress
go ahead \n");
/* "this should be \" removed" I should be here "but kill me here " */
}
*****************************************************************************
output should look like
**********************************************************************
#include <stdio.h>
int main ()
{
char c = '"';
printf();
printf ();
/* I should be here */
}
******************************************************************************
but with my version of perl script I get the output something like
this:
******************************************************************************
#include <stdio.h>
int main ()
{
char c = '"';
printf();
printf ();
/* "this should be \" removedbut kill me here " */
****************************************************************************
Can someone help me to get this regular expression correct??
Thanks
-Vittal
I am trying to write a perl script which removes the contents between
two plain double quotes. (I am parsing C and C++ files.) What I mean
by plain is, double quote (") should not have been preceeded by single
quote (') or back slash(\).
For this I wrote the following code, which is serving the purpose but
partially.
*******************************************************************************
#!/usr/bin/perl
open FILE , "./y.c";
while (<FILE>)
{
$temp .= $_;
}
$temp1 = $temp;
while ($temp && $temp =~ /[^'\\]("([^"])*")/s)
{
$find = $1;
$temp = $';
if (!($2 =~ /['\\]/)){
$temp1 =~ s/\Q$find//;
}
}
print $temp1;
******************************************************************************
So if I have a .c file like this:
******************************************************************************
#include <stdio.h>
int main ()
{
char c = '"';
printf("I should be removed \n");
printf ("Testing under proggress
go ahead \n");
/* "this should be \" removed" I should be here "but kill me here " */
}
*****************************************************************************
output should look like
**********************************************************************
#include <stdio.h>
int main ()
{
char c = '"';
printf();
printf ();
/* I should be here */
}
******************************************************************************
but with my version of perl script I get the output something like
this:
******************************************************************************
#include <stdio.h>
int main ()
{
char c = '"';
printf();
printf ();
/* "this should be \" removedbut kill me here " */
****************************************************************************
Can someone help me to get this regular expression correct??
Thanks
-Vittal