Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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 imbibing at the Monastery: (5)
As of 2014-08-29 03:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls