Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Modify C comment removal code to kill newlines

by borisz (Canon)
on Aug 21, 2006 at 14:03 UTC ( #568546=note: print w/ replies, xml ) Need Help??


in reply to Modify C comment removal code to kill newlines

Hi, here is another solution.

use Regexp::Common qw/comment/; local $/; $_ = <DATA>; s/$RE{comment}{C}\n*//gm; print; __DATA__ /* I have good commenting style */ i = 1; /* And I comment every line of code */ i++; /* Even if it's pointless */ j = i; j++;
Boris


Comment on Re: Modify C comment removal code to kill newlines
Download Code
Re^2: Modify C comment removal code to kill newlines
by anjiro (Beadle) on Aug 21, 2006 at 14:32 UTC
    Nice try, but on the original example this gives:
    void function foo(void) { int i; int j; i = 1; j = 1; i++; j++; }
      Ok, try this. It looks perfect to me on UNIX.
      use Regexp::Common qw/comment/; local $/; $_ = <DATA>; s/(^[ \t]*$RE{comment}{C}\n|$RE{comment}{C})//gm; print; __DATA__ /*This is a bogus function*/ void function foo(void) /*My function is the best*/ { int i; /*i is an integer*/ int j; /*j is also an integer*/ /*Now I'm going to set i to 1*/ i = 1; /*Also j*/ j = 1; /*Here's some incrementing!*/ i++; /*And more!*/ j++; /*The end!*/} __OUTPUT__ void function foo(void) { int i; int j; i = 1; j = 1; i++; j++; }
      Boris
        Congratulations, sir! You are a winner! Works perfectly on my horrible convolutedly commented code!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://568546]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2015-07-06 03:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls