Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by kcott (Abbot)
on Mar 24, 2013 at 07:48 UTC ( #1025127=note: print w/ replies, xml ) Need Help??


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

G'day FloydATC,

Perhaps something like this would be more to your liking:

$ perl -Mstrict -Mwarnings -le ' my @vlans = (2, 3, 4, 7, 10, 11, 12, 20); my $last = $vlans[0] - 2; my @ranges; push @{$ranges[$#ranges + ($_ - $last > 1)]}, $last = $_ for @vlan +s; print join ",", map { $_->[0] == $_->[-1] ? $_->[0] : join "-", @{$_}[0, -1] } + @ranges; ' 2-4,7,10-12,20

-- Ken


Comment on Re: Converting a list of numbers to use a range operator
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2014-09-21 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (166 votes), past polls