in reply to Is there a more functional regex syntax?
G'day smls,
In the code below, I've eliminated both temporary variables and reduced the foreach block of code to a single line:
$ perl -Mstrict -Mwarnings -e ' my @ranges = qw{15 28-31 3-4 40 17-19}; my ($total_min, $total_max); s{^(\d+)-?(\d*)$}{$total_min += $1; $total_max += $2 ? $2 : $1}e for @ +ranges; print "total is between $total_min and $total_max\n"; ' total is between 103 and 109
-- Ken
|
|---|