Thanks Ted,

Those last 2 worked great,  If I read this right

$file =~ s/\b(CREATE\s+TABLE[^;]+)//g unless $t;

find any CREATEwhitespaceTABLEanycharsnot; and replace them with ''.  the
whole lot of it has to start at a word boundary.

$file = join('', $file =~ m/\b(CREATE\s+TABLE[^;]+)/g) if $t;

I've never done this before, I didn't know you could produce a  list from a
match command.

Thanks again
Jay

----- Original Message -----
From: "Ted Deppner" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, September 13, 2001 12:22 AM
Subject: Re: [vox-tech] Looking for 2 cool regexs


> On Wed, Sep 12, 2001 at 04:25:47PM -0500, Jay Strauss wrote:
> > I have a flag in my pgm that indicates to look for "create table"
statements
> > OR anything else.  The end result I'd like is that my scalar ($rebuilt)
will
> > equal all the create table statements, or everything else.
>
> > a couple of regexs, one to null out anything not a "create table"
statement,
> > one to null out all the "create table" statements.
> >
> > But alas, I don't know how.
> >
> > I run my pgm by:
> >
> > # cat sample.data | tmp
> >
> > Jay
> >
> > #!/usr/bin/perl
> >
> > undef $/;
> > my $file = <>;
> > $file =~ s/\bREM\s+//g;
> > $file =~ s/\n//g;
> >
> > my $flag = "t";
> > my $rebuilt = '';
> >
> > foreach my $line (split(/;/,$file)) {
> >
> >    $create = ($line =~ /^CREATE\s+TABLE/) ? 1 : 0;
> >
> >    if ($flag eq "t") {
> >       $line = '' if ! $create;
> >    }
> >    else {
> >       $line = '' if $create;
> >    }
> >
> >    $rebuilt .= $line.";" if ($line);
> > }
>
> this loop can be :
>
>   $file =~ s/(;?\s*)(CREATE\s+TABLE[^;]+)(.*)/$1$3/g unless $t;
>   $file =~ s/(;?\s*)(CREATE\s+TABLE[^;]+)(.*)/$2/g if $t;
>
> which should simplify to (and should run faster)
>
>   $file =~ s/\b(CREATE\s+TABLE[^;]+)//g unless $t;
>   $file = join('', $file =~ m/\b(CREATE\s+TABLE[^;]+)/g) if $t;
>
> though I don't use \b often enough to be sure of its operation in every
> sitation.
>
> (should be close... (;?\s*) is a weak attempt to avoid CREATE TABLE inside
> strings... (you used \b instead)...   if you did a:
>   $file=join(";\n", split(/;/, $file)) . ";\n";
> you could use s///m for multiline, and then use ^ and $ for "start of
line"
> from a \n perspective.)
>
> > foreach my $line (split(/;/,$rebuilt)) {
> >   print substr($line,0,80)."\n";
> > }
>
> this hard coded 0,80 is suspect, but if your input data is assured it's
> not a problem (which doesn't appear to be the case).  You'll also lose
> your ; characters.
>
> --
> Ted Deppner
> http://www.psyber.com/~ted/


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

Reply via email to