Venerable monks

I have downloaded some code which is supposed to convert mssql database create statements into mysql create statements but it isn't working. The create table statement is supposed to have a semi colon at the end but it isn't getting one. Here is the relevant section of code to read in a mssql schema from file and convert to mysql. I'm guessing the faulty bit is in the top few lines

sub convert_schema { my ($name,$schema,$engine) = @_; my $schema2 = ''; my @lines = split "\n",$schema; for (@lines) { # CHANGES FOR ALL TABLES s#[\[\]]##g; # Remove brackets s/\)\n/\);\n/; # Add semicolon to end of table statemen +t s/char \(/char(/; # Remove space between varchar and ( s/ ,/,/g; # Remove space before comma s/ varchar\(\d+\)/ text/ if (m/varchar\((\d+)\)/) and ($1 > 255); +# Use "text" instead of "varchar(n)" if n > 255 s/\)$/\);/; s/ smalldatetime/ varchar(32)/g; # Trouble w/dbSNP dates, like "20 +00-08-25 17:02:00.0" - the .0 at the end. s/ datetime/ varchar(32)/g; s/ real/ float/g; s/ bit/ boolean/g;
this is what is created - note the absence of semi colon
CREATE TABLE Allele ( allele_id int NOT NULL, allele varchar(255) NOT NULL, create_time varchar(32) NOT NULL, rev_allele_id int NULL, src varchar(10) NULL, last_updated_time varchar(32) NULL )
here is a mssql create table
CREATE TABLE [Allele] ( [allele_id] [int] NOT NULL , [allele] [varchar] (255) NOT NULL , [create_time] [smalldatetime] NOT NULL , [rev_allele_id] [int] NULL , [src] [varchar] (10) NULL , [last_updated_time] [smalldatetime] NULL )
I don't understand why this doesnt work. The regular expression looks ok to me
s/\)\n/\);\n/;
It seems to be looking for a bracket followed by a new line and replacing with with a bracket followed by a semi colon and a newline? But it isn't working. It isn't detecting the \)\n bit because if i take out the \n bit it replaces all brackets but if i add the \n back it doesn't detect anything

thanks for any help

In reply to regular expression code not working by Anonymous Monk

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.