Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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 $_ ; }


Comment on Re: Regex: Identifying comments
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (18)
As of 2015-07-06 14:16 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 (75 votes), past polls