in reply to Re^4: C style multiple line comment removal
in thread C style multiple line comment removal

That is C. We're trying to help you with your Perl code, as this is a Perl forum. Where is your Perl code that is failing?


Dave

  • Comment on Re^5: C style multiple line comment removal

Replies are listed 'Best First'.
Re^6: C style multiple line comment removal
by prassi (Acolyte) on Jun 08, 2012 at 08:54 UTC

    Sorry here is the perl code.

    #!/bin/perl5.8.6 $flag = open(file1, "main.c"); $flag2 = open(file2, ">main_out.c"); if(flag && flag2){ while(!eof(file1)){ $line = <file1>; $/ = undef; $_ = <file1>; s#(/\*.*?\*/)|//[^\n]*|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)# +defined $2 ? $2 : ""#gse; print file2 ($_); } } close(file1); close(file2);
    Thanks for your time
      To start with: After entering the loop you are reading the first line ($line = <file1>) and throw it away (because $line is never be used again), so from this alone we can conclude that you won't recognize a comment which starts in the first line. You would have found this immediately, if you had included use strict; use warnings FATAL => 'all'; in your code.

      There are more problems in your code, but I suggest you first enable strict and warnings, then try to improve the code (based on what I told you above), and if you still can't get it running, post your updated code here.
      -- 
      Ronald Fischer <ynnor@mm.st>

        Thanks Ronald, got my mistake and it is working fine. Im new into perl learning a lot thanks for your help