Actually, $1, $2, ... get reinitialized only if there is a match, so if
the subsequent regexes didnt' match, he'd still have the original $2
__END__
=sincerely, eduard grinvald
=email: [EMAIL PROTECTED]
=icq: 114099136
=PGP: http://i5.nyu.edu/~eg344/pgp_public
=cut
----- Original Message -----
From: Akshay Arora <[EMAIL PROTECTED]>
Date: Wednesday, July 11, 2001 11:39 am
Subject: Re: Why wont my REGEX match..
> There is nothing in $2, because every time you do a RegExp, all of
> thosevariables get initialized.
>
> You do a $opt =~ s/ //g; before you request $2
> do the $value = $2 before that line, and you will be fine.
>
> -Akshay
>
> Hamish Whittal wrote:
> >
> > Hi All,
> >
> > I have the following lines from a config file I am trying to read:
> > {wellfleet ASN} .1.3.6.1.4.1.18.3
> > (agentType) .1.3.6.1.4.1.18.3.3.1.11
> > (chassisType) .1.3.6.1.4.1.18.3.1.1.1
> >
> > My code is:
> > if ( $_ =~ /\{(.*)\}\s+(.*)/ ) {
> > $dev = 1;
> > $opt = lc($1);
> > $opt =~ s/ //g;
> > $value = $2;
> > } elsif ( $_ =~ /\s*\((.*)\)\s+(.*)/ ) {
> > $oid = 1;
> > $opt = lc($1);
> > $opt =~ s/ //g;
> > $value = $2; #the OID of for this device
> > } else {
> > die ("Config file is badly built"); }
> >
> > The $1 works fine in the 1st if, but $2 will not return the
> .1.3.6.....> Instead it return an empty string. Any clues.
> >
> > Thanks in advance.
> > H
> >
> > --
> > Hamish Whittal QED Technologies Tel: +27
> 21 448 9291
> > [EMAIL PROTECTED] Fax: +27
> 21 448 9551
> > `The' Linux Services Company Cel: +27
> 82 803 5533
>