Instead of one big regexp that splits the line you could consume it chunk by chunk, which lets you break the regexp into smaller pieces and give names to the fields.

In any case you will have to deal with the fact that (s and )s have to be escaped so it will look ugly no matter what you try. Is there a Perl 6 RFC that would allow us to change that character?

Update: I have worked on the display part too, and figured that as naming things is good I should go all the way and use a hash to store the 3 parts of the SQL instruction. Plus I am not very familiar with hash slices so it was a good opportunity to use one ;--)

#!/bin/perl -w use strict; my ( @results, %fields ); my $TABLE= 'Photo'; while(<DATA>){ s/\0//g; if ( s/(?<!from )(INSERT INTO $TABLE\s*)//) { my $table= $1; # easy to get +it here my $fields= $1 if( s/(\([^(]+\))//); # the complex +one my $values= $_; # just grab th +e rest push @results, { table => $table, # naming thing +s is good! fields => $fields, values => $values }; } } my @final = sort{ $a->{fields} cmp $b->{fields} } @results; # the so +rt is easier to understand open OUT, ">results.txt" or die $!; foreach my $insert ( @final ) { my $fieldNames = $insert->{fields}; if ( ! exists $fields{ $fieldNames } ) { $fields{ $fieldNames } = 1; print @$insert{qw(table fields values)}; # and n +ow the hash slice } } close OUT; __DATA__ go INSERT documents ( did, DocID, Template ) VALUES ( 3093, '000000000000 +000000003093', 'Photo' ) go SELECT * FROM documents WHERE did=3093 go INSERT INTO Photo (AccessLevelID, ANRNumber, ColorID, ContactSheetID) +VALUES (1, '225058', 1, 4) go exec new_int_id 'Photo', 'PhotoID' go exec new_str_id 'documents', 'DocId' go INSERT INTO Photo (QualityID, Remark, UniqueID, VolNum) VALUES (1, 'St +. Nicolaasfeest -v. Moorsel', '211357', '1') go

In reply to Re: Trying to avoid line noise (brain cramp) by mirod
in thread Trying to avoid line noise (brain cramp) by Ovid

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.