Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Regex: Identifying comments

by pvaldes (Chaplain)
on Aug 30, 2012 at 10:06 UTC ( #990708=note: print w/replies, xml ) Need Help??

in reply to Regex: Identifying comments

The comments in a sql file will be probably either at the start of the line with or without white spaces "^\s*--" or after a semicolon "\;\s*--". If I'm not wrong, this is not a valid sql sentence in most databases, thus you shouldn't have it:

select '--foo' from mytable --bar

(And you shouldn't have tables with name fields beginning by "--")

Something like this should be enough to strip all comments from your file:

open my ORIGINALFILE, '<', 'file.sql' or die... etc open my CLEANEDFILE, '>', outfile... etc, as usual while (<ORIGINALFILE>){ next if /^\s*--.*$/ ; s/\;\s*--.*$/;/ ; print CLEANEDFILE $_ ; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990708]
and all is calm...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2018-05-26 01:16 GMT
Find Nodes?
    Voting Booth?