Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Get ranges from a list of numbers (like 1,2,3 => 1-3)

by aitap (Deacon)
on Apr 09, 2013 at 16:46 UTC ( #1027782=note: print w/replies, xml ) Need Help??

in reply to Get ranges from a list of numbers (like 1,2,3 => 1-3)

Well, searching "range from list" reveals the thread: [Solved] Converting a list of numbers to use a range operator, which suggests using Set::IntSpan's run_list method:
my @array = (2,3,4,10,11,12); my $set = new Set::IntSpan join(',', @array); my $list = $set->run_list; # $list is now "2-4,10-12"

Replies are listed 'Best First'.
Re^2: Get ranges from a list of numbers (like 1,2,3 => 1-3)
by Doctrin (Beadle) on Apr 09, 2013 at 19:04 UTC
    Thank you! That is exactly what I need!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027782]
[chacham]: ought to be a check constraint.
[chacham]: there's a regexp function. if that can be used ina check() constraint...
[LanX]: Thanks, but no check constraints in MySQL :/
LanX 1 ..2 ..3 ..4 .. is erix missing ;-)
LanX is Discipulus reciting "Springtime for Hitler" ?
[choroba]: erix could tell you how to do it in Postgres
[chacham]: wow, mysql really is as bad as i thougt
[choroba]: completion?

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2017-03-30 15:06 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (360 votes). Check out past polls.