[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: regex question
On Wed, Apr 11, 2001 at 06:35:03AM -0700, Robert Threet wrote:
> Actually, I want to grab the serial number and stuff
> it into $oldserial.
That's what the code I suggested does (note the single equals sign). Try it,
it works (assuming you actually have the string "serial" after 10 digits
and some other chars). Granted, it's kinda inefficient since it's assigning
$1's value to $oldserial each time through the loop and then testing to
see if that value's null or not, but since the serial's early in the file,
it's not a big deal.
> As for the alternatives... I know what you mean but I
> wouldn't know how to implement it. *I* understand the
> way *I* want to do it (even if Perl doesn't). I'm
> afraid I may have to reverse that. :-)
I'm pretty sure this'll do it the "slightly more reliable" way...
# read whole file into var
$contents = join('', <DB>);
# strip comments
$contents =~ s/;.*\n/\n/g;
# pull out first set of one or more digits after whitespace after a
# parenthesis after SOA and some chars
$contents =~ /SOA.*\(\s*(\d+)/;
$oldserial = $1;
--Danny
> --- Danny Sauer <sauer@cloudmaster.com> wrote:
> > On Tue, Apr 10, 2001 at 01:20:16PM -0700, Robert
> > Threet wrote:
> > > If I have the following:
> > >
> > > while (<DB>) {
> > > next unless (/(\d{10}).*serial/);
> > > $oldserial=$1;
> > > last;
> > > }
> > >
> > > I would've thought this would find the serial
> > number
> > > in a DNS db file and return it as $1, then break
> > out
> > > of the loop. It seems to break out of the loop
> > and is
> > > null. I'm pretty fuzzy on regex and this way of
> > > breaking out of a loop but I can't think of a
> > better
> > > way. Does anybody see what I'm doing wrong?
> >
> > I'm guessing that there's a scope problem there, but
> > am not sure
> >
> > Why not
> >
> > while (<DB>) {
> > /(\d{10}).*serial/;
> > last if ($oldserial = $1);
> > }
> >
> > As a side note, wouldn't it be safer to look for the
> > SOA line, then just
> > grab the first series of numbers after the "("? (not
> > to mention that I've
> > got 9-digit serials... :))
-
To unsubscribe, send email to majordomo@luci.org with
"unsubscribe luci-discuss" in the body.