Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Re-use of a global match

by balaji_red83 (Acolyte)
on Aug 01, 2007 at 13:25 UTC ( [id://630048]=note: print w/replies, xml ) Need Help??


in reply to Re-use of a global match

It is better not to use /g modifier while performing match operation.

Replies are listed 'Best First'.
Re^2: Re-use of a global match
by mr_mischief (Monsignor) on Aug 01, 2007 at 14:11 UTC
    That statement needs to be qualified. It is far from always true. The /g modifier is part of Perl for a reason and there are many things one can do with it that are much more difficult without it.
    $foo = (join ', ', 'abacadaeafagahaiaj' =~ m/a/g ); print $foo . "\n";
      /g can be useful. But if you just want to know if something matches (which for me is most of the time), you don't need it.

      The cases where m///g is useful are where:

      • you need to save the position of the last match, or
      • you're counting or saving the matches for later use (assigning the result of m/// to a variable)

      In practice, I find myself using /g only in substitutions.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2026-04-10 22:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.