l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
November 4: Social gathering
Next Installfest:
TBD
Latest News:
Oct. 10: LUGOD Installfests coming again soon
Page last updated:
2001 Dec 30 17:10

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] Looking for 2 cool regexs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] Looking for 2 cool regexs



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" <ted@psyber.com>
To: <vox-tech@franz.mother.com>
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


LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Sunset Systems
Who graciously hosts our website & mailing lists!