in reply to joining lines efficiency?

Another option is the flip-flop operator: Read the file line-by-line, and don't print if between an opening expression and closing expression.

The general idea is print unless /<expr1>/ .. /<expr2>/, but here the slash and star need to be escaped.

while(<$fh>){ print unless m{/[*]} .. m{[*]/}; }

Replies are listed 'Best First'.
Re^2: joining lines efficiency?
by hdb (Monsignor) on Jun 10, 2013 at 05:36 UTC

    While your proposal needs less memory, it can go wrong as well. Should the comment start or end on a line with code outside of the comments, the whole line and the code will be removed. The regex also needs to be more sophisticated to ignore "/*" ie should the characters be quoted.

      The regex also needs to ... ignore "/*" ie should the characters be quoted.

      It should also handle stuff like this, which compiles and runs just fine:

      #include <stdio.h> #include <assert.h> void main (int argc, char ** argv) { int x = 4; int y = 2; int * p = &y; assert(x/*p == 12345 /* p points to y */); printf("everything looks just fine \n"); }