#!/usr/bin/perl

use 5.6.0;
use strict;
use warnings;

sub format_number_list {
	my @output ;
	while (@_) {
		my $range_start = shift;
		my $range_end = $range_start;
		# check if the numbers go in sequence from here
		$range_end = shift while (@_ && $_[0] == $range_end + 1);
		# ...and add to output accordingly
		if ($range_start == $range_end) { push @output, $range_start; }
		else { push @output, "$range_start-$range_end"; }
	}
	join ", ", @output;
}

# split chunks and map ranges to their expansion (with bug work around)
sub expand_number_list {
	return map { /^(-?\d+)-(-?\d+)$/ ? $1+0..$2+0 : $_ } split /, /, shift;
}

