Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: What does 'global' (/g) do in a regexp in this particular case?

by LanX (Canon)
on Apr 09, 2013 at 13:37 UTC ( #1027738=note: print w/ replies, xml ) Need Help??


in reply to What does 'global' (/g) do in a regexp in this particular case?

/g in scalar context iterates over all matches and keeps track of the position, see also pos

Without /g the match restarts from the beginning, i.e. the string is stateless.

DB<116> $a="a a" => "a a" DB<117> scalar ($a =~ /a/g) => 1 DB<118> scalar ($a =~ /a/g) => 1 DB<119> scalar ($a =~ /a/g) => "" # exhausted DB<120> $a="a a" => "a a" DB<121> scalar ($a =~ /a/) => 1 DB<122> scalar ($a =~ /a/) => 1 DB<123> scalar ($a =~ /a/) => 1 # ... till infinity

Cheers Rolf

( addicted to the Perl Programming Language)


Comment on Re: What does 'global' (/g) do in a regexp in this particular case?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027738]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2015-07-03 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (56 votes), past polls