#!/usr/bin/perl -w
use strict;
use Data::Dumper;

sub format_number_list {
    my @int_list = sort { $a <=> $b } @_;
    my @sets;
    while (my @seq = chew_seq(\@int_list)) {
        push @sets, $seq[0] . ($seq[-1] ? "-$seq[-1]" : "");
    }
    return join ", ", @sets;
}

# chew_seq checks to see if it's argument (a ref to an array) has,
# at the beginnig, a sequence of increasing integers. it removes
# this sequence from the arg and returns it.
sub chew_seq (\@) {
    my $list = shift(@_);
    return unless @$list;
    my @seq = shift @$list;
    while (@$list &&
           ($list->[0] == $seq[-1] + 1)) {
        push @seq, shift @$list;
    }
    return @seq;
}

sub expand_number_list {
    my $int_list = shift;
    join ", ", map { /^(\d+)-(\d+)$/ ? $1 .. $2 : $_ } split /, +/, $int_list;
}

1;

__END__

my $s = fnl(1,2,3,6,10,11,12,13,14,18,90,91,92,100);
my @s = enl($s);

print Dumper(\$s, \@s);

