Hi everyone,
Sorry for asking this question again for what must be the umpteenth time but I have a problem with
the g modifier when matching. I have read Newsgroup Postings about this topic including:
"What good is \G in a regular expression?"


Listed below is what I'm experiencing problems with:

$PARSE{"letter"} = "([A-Z])";
$PARSE{"number"} = '(\d{1,2})';

$src = "a 1 b 2 c 3";

if($src =~ m/$PARSE{"number"}/sgi)
{
        $num = $1;
}

if($src =~ m/$PARSE{"letter"}/sgi)
{       
        $let = $1;
}

print "Number: $num\n"; #-->(Prints "1")
print "Letter: $let\n";#-->(Prints "b")
#(Prints "a") <-> If Letter Matching Comes First then  Number Matching
# OR
#(Prints "a") <-> Without g Modifier

Based on FAQ 6.19, I'm trying to understand why Precedence matters when using the g Modifier when matching
part of a string, even when that string hasn't been modified.
I don't have any problems when using the g Modifier in a Loop, for some reason.


From FAQ 6.19:
The notation "\G" is used in a match or substitution in conjunction with
the "/g" modifier to anchor the regular expression to the point just
past where the last match occurred, i.e. the pos() point.


Thanks in advance.
-gohaku


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to