prassi has asked for the wisdom of the Perl Monks concerning the following question:
I am intend to remove C and C++ style comment from a C code. In the below perl script I am reading from a file, modifying and writing into another file.
Now my question I need to write into the same file as when I modify line. If I open the file in write mode it is not working. Please help me how do I write into the same file and at the same line.
#!/bin/perl5.8.6 $flag = open(file1, "main.c"); $flag2 = open(file2, ">main_out.c"); if(flag && flag2){ while(!eof(file1)){ $/ = undef; $_ = <file1>; s#(/\*.*?\*/)|//[^\n]*|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)# +defined $2 ? $2 : ""#gse; print file2 ($_); } } close(file1); close(file2);
Regards, =Prasad
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: modifying in the same file
by Illuminatus (Curate) on Jun 08, 2012 at 19:04 UTC | |
|
Re: modifying in the same file
by davido (Cardinal) on Jun 09, 2012 at 00:15 UTC | |
|
Re: modifying in the same file
by zentara (Cardinal) on Jun 08, 2012 at 18:39 UTC |