Platinum Partner

Expand Numerical Ranges

This rather long winded Perl subroutine returns an array of numbers expanded from a list such as 34,35,36,42-56,98-150. There are plenty of other ways to do this (eval comes to mind).


 sub expand {                                                              
  my $range = shift;            
  my @result; 
$range =~ s/[^\d\-\,]//gs; #remove extraneous characters
 my @items = split(/,/,$range);    
  foreach (@items){                 
    m/^\d+$/ and push(@result,$_) and next;  my ($start,$finish) = split /-/;   push(@result,($start .. $finish)) if $start < $finish;                    
  }                                 
  return @result;                        
 } 
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}