I have an array of numbers:
@numbers = 1,2,3,6,8,9,11,12,13,14,15,20
and I want to print it this way:
1-3,6,8-9,11-15,20
Any thoughts? Of course I tried using the most common "looping", but still didn't get it.
You can use Set::IntSpan::Fast:
use Set::IntSpan::Fast;
my @numbers = (1,2,3,6,8,9,11,12,13,14,15,20);
my $set = Set::IntSpan::Fast->new;
$set->add(@numbers);
print $set->as_string, "\n";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With