Hamish, your regex's seem to work OK, and so does the elsif (at least in the
slightly modified test case I'm using). How do you know the elsif is not
executing/matching? You are looping through your config file a line at a
time I assume. Anyway, here's the test code I ran which worked, using as the
input a file containing just the three lines of example you gave. It misses
out a few lines of your code but nothing which should cause any problems:

open IN, "test.config";
while (<IN>) { 
# substitute 'while ($line = <IN>)' if you want to use $line in the match
tests

  if (m/\{(.*)\}[\s\t]+(.*)/ ) {
    $value = $2;
    $opt = lc($1);
    print "'if' block - $opt, $value\n"; # Just to let us know whether it's
worked
  }
  elsif (m/[\t\s]*\((.*)\)[\s\t]*(.*)/) {
    $value = $2;
    $opt = lc($1);
    print "'elsif' block - $opt, $value\n";
  }
  else {die "Config file is badly built"}
}

Sorry I can't find anything to actually solve your problem - I can only
guess that it's a problem with the way you're reading in the config file or
something else outside of your code example.

Cheers

Mark C

> -----Original Message-----
> From: Hamish Whittal [mailto:[EMAIL PROTECTED]]
> Sent: 16 July 2001 13:48
> To: [EMAIL PROTECTED]
> Subject: Re: Why wont my REGEX match..
> 
> 
> 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 ( $line =~ m/\{(.*)\}[\s\t]+(.*)/ ) {
> >           $dev = 1;
> >           $value = $2;
> >           $opt = lc($1);
> >           $opt =~ s/ //g;
> >        } elsif ( $line =~ m/[\t\s]*\((.*)\)[\s\t]*(.*)/ ) {
> >                $oid = 1;
> >                $value = $2; #the OID of for this device
> >                $opt = lc($1);
> >                $opt =~ s/ //g;
> >        } else {
> >             die ("Config file is badly built"); }
> Problem is: My first Regex matches the {} brackets, but the 
> elsif either
> never executes, or the regex does not match. I have tried using the
> elsif in an egrep, and it does match the () in the config 
> file, so I am
> sure that I have the regex done fine.
> 
> Any comments would be most helpful.
> 
> Thanks
> Hamish
> 
> 
> -- 
> 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
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to