Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^6: Regex: Identifying comments

by pvaldes (Chaplain)
on Aug 31, 2012 at 15:32 UTC ( #991028=note: print w/replies, xml ) Need Help??

in reply to Re^5: Regex: Identifying comments
in thread Regex: Identifying comments

use strict; use warnings; while (<DATA>) { chomp; next if /^\s*--/; print $_,"\n" if !/--/; elsif (/--/ && !/--(.*?);/){ s/--(.*?)$//; print $_,"\n"} elsif (/--(.*?);\s*--(.*?)$/){ s/\s*--$2//; print $_,"\n"} else { print $_,"\n"} } __DATA__ select 'text' from foo; -- comment select '--Not comment' from foo; --But this is select q from z; -- as is this select '--Not this' + '--either' from foo; select 'qaws' + make from "a"; -- comment with 'a' quote select 'a' from 'b' with 'c' -- comment with 'a --' comment -- test comment (add1) select 'text\'s' from foo --escaped ... (add2) select 'text\'s' from foo --escaped' ... (add3) update set bar = bar - 1 ; -- subtraction symbol preserved create table ( -- fo field text, -- fufufu field int)

Replies are listed 'Best First'.
Re^7: Regex: Identifying comments
by hbm (Hermit) on Sep 01, 2012 at 14:49 UTC

    I think you need to revisit this...

    syntax error at line 7, near "elsif" syntax error at line 10, near "elsif" syntax error at line 12, near ""\n"}" Execution of aborted due to compilation errors.
      first elsif should probably be "if" only

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991028]
and a log crumbles through the grate...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2018-05-22 21:51 GMT
Find Nodes?
    Voting Booth?