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
In reply to modifying in the same file by prassi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |