Am�rico Albuquerque wrote:

> Hi
> 
> I have a config file that can have three formats:
> "[alpha] [alpha]", "[alpha]: [alpha]" or "[alpha] *[alpha]"
> 
> So I made 3 regexp to check each variation:
> $line1 =~ /\s*([\w-_\.]+)\s+([\w-_\.]+)/;
> $line2 =~ /\s*([\w-_\.]+):\s*([\w-_\.]+)/;
> $line3 =~ /\s*([\w-_\.]+)\s+\*([\w-_\.]+)/;

'\w' includes '_' already and '-' has to be first or last if not used
to denote a range; should be [\w\.-]

> the problem is that $1 and $2 keep the falues of the previous match. 
> That means that I can't see if a match was foud unless I have to test it 
> for each line.
> Is there a way to clear the matched subexpressions of the $1...$9 
> variables or do I have to check each line to see what test applies?

Put each expression into a separate block and it should be fine.

use strict;
use warnings.

my @strings = ('A B', 'C: D', 'E *F');

foreach (@strings) {

{       # extra bracketing block to clear $1..$9

        print "1A: $_\n";
        for (1..9) { eval "print \"$_: \", \$$_, \"\n\" if defined \$$_"; }
        if (/\s*([\w\.-]+)\s+([\w\.-]+)/) {
                print "1B: $_\n";
                for (1..9) { eval "print \"\t$_: \", \$$_, \"\n\" if defined 
\$$_"; }
        }
}

{       # extra bracketing block to clear $1..$9
        print "2A: $_\n";
        for (1..9) { eval "print \"$_: \", \$$_, \"\n\" if defined \$$_"; }
        if (/\s*([\w\.-]+):\s*([\w\.-]+)/) {
                print "2B: $_\n";
                for (1..9) { eval "print \"\t$_: \", \$$_, \"\n\" if defined 
\$$_"; }
        }
}

{       # extra bracketing block to clear $1..$9
        print "3A: $_\n";
        for (1..9) { eval "print \"$_: \", \$$_, \"\n\" if defined \$$_"; }
        if (/\s*([\w\.-]+)\s+\*([\w\.-]+)/) {
                print "3B: $_\n";
                for (1..9) { eval "print \"\t$_: \", \$$_, \"\n\" if defined 
\$$_"; }
        }
}

}

__END__


-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to