Hi all

I've a simple problem I can't solve by myself, I apologize for that.

I want to clean up a mysql database, derived by ms access, with spaces where they shouldn't be, parsing/reading a mysqldump and converting spaces into underscores...

for example:

create table `table name`( `field name1` type1 not null default 'x', `field name2` type2 default null, ... primary key (`pk name`), key `key name` (`field name1`, `field name2`) ) engine=other things here;
I would like this converted to:
create table `table_name`( `field_name1` type1 not null default 'x', `field_name2` type2 default null, ... primary key (`pk_name`), key `key_name` (`field_name1`, `field_name2`) ) engine=other things here;
this means that everything in the format of:
m/`\w+\s+\w+[\s+\w+]+`/ # backticks

should be transformed into a string with spaces converted to underscores (another option could be the camel case: something like `field name` into: `fieldName`)

I understand there must be a very efficient and compact solution, but I'm losing myself in a sql parsing without success.

Please enlighten my way...


In reply to Regexp in mysqldump by brozzis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.