in reply to
Is there a more functional regex syntax?
A functional approach (more for fun though):
#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw(reduce);
use Data::Dump 'pp';
my @ranges = ('15', '28-31', '3-4', '40', '17-19');
my ($total_min, $total_max) = @{
reduce { [$a->[0] + $b->[0], $a->[1] + $b->[1]] }
map { @$_ == 1 and [($_->[0]) x 2] or $_ }
map { [ split /-/ ] } @ranges
};
pp ($total_min, $total_max);
__DATA__
('15', '28-31', '3-4', '40', '17-19')
|
v
([15], [28, 31], [3, 4], [40], [17, 19])
|
v
([15, 15], [28, 31], [3, 4], [40, 40], [17, 19])
|
v
[103, 109]