Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: Is there a more functional regex syntax?

by smls (Friar)
on Sep 18, 2012 at 17:14 UTC ( [id://994317]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Is there a more functional regex syntax?
in thread Is there a more functional regex syntax?

Thank, this is what I've been looking for!

It's not extremely pretty, but it should scale nicely for the general case of needing the result of a regex string extraction as a right-hand-side value.

PS: The regex suggested by tobyink above can make the single-line case much more readable: /(\d+)/g

Replies are listed 'Best First'.
Re^4: Is there a more functional regex syntax?
by kennethk (Abbot) on Sep 18, 2012 at 17:35 UTC
    The regex suggested by tobyink above can make the single-line case much more readable

    The advantage of mine is that it actually enforces format, which may or may not be of concern. I also like that you expect two values and you get two values; a little less slight of hand for maintenance. But I do appreciate the elegance of his choice of indices.

    Also be aware you'll need to initialize @totals = (0,0) so that the index -1 doesn't map to your first term. tobyink does it, but didn't really emphasize its importance.


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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-19 04:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found