Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: joining lines efficiency?

by hbm (Hermit)
on Jun 10, 2013 at 02:32 UTC ( #1037976=note: print w/replies, xml ) Need Help??


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"); }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2021-09-22 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?