Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: callback for regex engine

by kennethk (Monsignor)
on Jun 20, 2013 at 23:38 UTC ( #1040040=note: print w/ replies, xml ) Need Help??


in reply to callback for regex engine

LanX has a good answer. So, moving on and proselytizing, regular expressions give you enough power that if you feel like you need an internal callback, you are probably using them wrong. For the case of counting 's' in a string, the easiest answer is

$count = $var =~ tr/s/s/;
as documented in How can I count the number of occurrences of a substring within a string? in perlfaq4. I try to keep regular expressions short and sweet, and if I need really complex logic, I write that in Perl so that it's more than line noise to the casual observer.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


Comment on Re: callback for regex engine
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-07-25 23:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls