http://www.perlmonks.org?node_id=994314


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

Or, as an improvement in the regex, /^(?=(\d+))(?:\d+-)?(\d+)$/, so that both $1 and $2 are always defined. So, as 1 line,
$totals[$_] += ($range =~ /^(?=(\d+))(?:\d+-)?(\d+)$/)[$_] for 0,1;
Or more simply, if you want to keep the variables separate,
$total_min += ($range =~ /^(\d+)/)[0]; $total_max += ($range =~ /(\d+)$/)[0];

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