Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Regexp in mysqldump

by clueless newbie (Hermit)
on Apr 16, 2010 at 16:02 UTC ( #835153=note: print w/ replies, xml ) Need Help??


in reply to Re: Regexp in mysqldump
in thread Regexp in mysqldump

Ignore the above! Try the following instead

#! use Smart::Comments; use strict; use warnings; my $sql=<<"__SQL__"; /* comment! */ create table `table name`( # another comment! `field name1` type1 not null default 'x has a blank or two', `field name2` type2 default null, # ... primary key (`pk name`), key `key name` (`field name1`, `field name2`) ) engine=other things here; __SQL__ my $RegExp_s=qr{( (`(?:[^`]|\`)*?`) # backticked string |(?:\/\*.*?\*\/) # /* */ comments |(?:'(?:[^']|\')*?') # single quoted strings |(?:"(?:[^"]|\")*?") # qouble quoted strings |(?m:\#.+?$) # single line # trailing comments )}sx; #' # . includes \n ### $sql $sql =~ s{$RegExp_s}{defined $2 ? TreatBackTickedString($2) : $1}eg; ### $sql sub TreatBackTickedString { # Jest Fur Phun: return substr($_[0],0,-1).substr($_[0],1); }; __END__


Comment on Re^2: Regexp in mysqldump
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2015-07-30 02:28 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 (269 votes), past polls