Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: [Perl 5.14, regex]: Problems with /g, \G and pos()

by moritz (Cardinal)
on Oct 19, 2013 at 16:15 UTC ( #1058930=note: print w/ replies, xml ) Need Help??


in reply to [Perl 5.14, regex]: Problems with /g, \G and pos()

The problem is that your regex potentially matches zero characters, so a loop like

while (/\s*/g) { ... }

Would loop infinitely. To prevent that, perl has some extra magic asociated with zero-width matches and /g, which you observe here. The obvious solution is to not use a regex which can match zero characters. You can prevent resetting of pos by using the /gc modifiers.


Comment on Re: [Perl 5.14, regex]: Problems with /g, \G and pos()
Select or Download Code
Re^2: [Perl 5.14, regex]: Problems with /g, \G and pos()
by Darkwing (Novice) on Oct 20, 2013 at 12:01 UTC
    Ah, well, that's reasonable. Thanks to you and to all others for help!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2014-07-25 07:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (169 votes), past polls