Vyacheslav Karamov wrote: > Rob Dixon пишет: >> >> foreach my $citation (@vancouverCites) { >> >> print qq(Text = "$citation"\n); >> >> while ($citation =~ /$regex/g) { >> print qq(pos = $-[0] to $+[0]\n); >> } >> print "\n"; >> } >> >> I hope this helps, >> >> Rob >> >> > Hi, Rob! > > I'm confused why your sample works with /g option and doesn't works > without it. > > P.S. I don't know why, but Thunderbird removes code indentation.
Without the /g qualifier the regular expression is just repeated endlessly (if it succeeds) or evaluated once (if it fails). So a construct like this while ($citation =~ /$regex/) { : } is of no use at all. Adding the /g qualifier changes things, however. This is from perldoc perlop > In scalar context, each execution of "m//g" finds the next > match, returning true if it matches, and false if there is no > further match. The position after the last match can be read or > set using the pos() function; see "pos" in perlfunc. so because the condition of a while statement is in scalar context, the body will be executed for each successful match of the regular expression on the object string. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/