Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Converting a list of numbers to use a range operator

by FloydATC (Chaplain)
on Mar 23, 2013 at 21:22 UTC ( #1025081=note: print w/ replies, xml ) Need Help??


in reply to Re: Converting a list of numbers to use a range operator
in thread [Solved] Converting a list of numbers to use a range operator

Yes!! Set::IntSpan, I knew I'd seen something like that but couldn't remember what it was called!

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"
Now this... this is not ugly :-)

-- Time flies when you don't know what you're doing


Comment on Re^2: Converting a list of numbers to use a range operator
Download Code
Re^3: Converting a list of numbers to use a range operator
by 2teez (Priest) on Mar 24, 2013 at 08:11 UTC

    I even love the way Parse::Range does it.
    Putting your original $list in the function parse_range prints out beautifully like so:

    use warnings; use strict; use Parse::Range qw(parse_range); my $list = "2-4,10-12"; print join ','=> parse_range($list); # 2,3,4,10,11,12

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1025081]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2014-12-20 22:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (99 votes), past polls