Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Is there a more functional regex syntax?

by BrowserUk (Pope)
on Sep 18, 2012 at 16:26 UTC ( #994310=note: print w/ replies, xml ) Need Help??


in reply to Is there a more functional regex syntax?

How's about:

use List::Util qw[ sum ]; my @ranges = ('15', '28-31', '3-4', '40', '17-19'); my $tMin = sum map{ /^(\d+)/ } @ranges; my $tMax = sum map{ /(\d+)$/ } @ranges; print "$tMin : $tMax";; 103 : 109

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

RIP Neil Armstrong


Comment on Re: Is there a more functional regex syntax?
Download Code
Re^2: Is there a more functional regex syntax?
by smls (Friar) on Sep 18, 2012 at 17:36 UTC

    I think this is the most readable solution for this specific problem posted so far, thanks for posting it.

    I have always shied away from List::Util and friends so far, but I'm starting to see its beauty...

      I have always shied away from List::Util ...

      Personally, I think List::Util should be incorporated into the core; so often do I use it in my programs.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      RIP Neil Armstrong

        Some parts of List::Util are a little ill-conceived. For example, the existence of separate min and minstr functions (and max/maxstr). Perl gets by with a single sort function that can take an optional block. Obviously there is a limit to what can be done with prototypes, but if List::Util were to be adopted into the Perl language itself, I'd hope that would be addressed.

        But certainly, the functions in List::Util would be a lot more useful in core than getgrent, setnetent and getgrgid.

        I'd also add uniq from List::MoreUtils and about half of Scalar::Util.

        perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2014-10-21 12:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (103 votes), past polls