in reply to Regexp in mysqldump
May I offer
which yields#! 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__ ### $sql my $RegExp_s=qr{(?: (`(?:[^`]|\`)*?`) # backticked string |(?:\/\*.*?\*\/) # /* */ comments |(?:'(?:[^']|\')*?') # single quoted strings |(?:"(?:[^"]|\")*?") # qouble quoted strings |(?m:\#.+?$) # single line # trailing comments )}sx; #' # . includes \n while ($sql =~ m{$RegExp_s}g) { if (defined $-[1]) { # backticked string substr($sql,$-[1],$+[1]-$-[1])=~ s/ /_/g; }; }; ### $sql __END__
Commented the regex.### $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: '/* 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; '
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Regexp in mysqldump
by clueless newbie (Curate) on Apr 16, 2010 at 16:02 UTC |
In Section
Seekers of Perl Wisdom