in reply to Array Exclusion Operationss
Fix all the problems that arise. Your problems will be much clearer now.use strict; use warnings FATAL => 'all';
As for your code, there are modules that deal with that. You really don't want to use eval. If you can't use modules for some reason, here's a version that should work for you (untested!):
sub get_numbers_from_ranges { my $spec = shift; my %numbers; foreach my $x ( split ',', $spec ) { if ( $x =~ /(\d+)-(\d+)/ ) { $numbers{$_} = undef for $1 .. $2; } else { $numbers{$x} = undef; } } return map { $_ - 1 } sort { $a <=> $b } keys %numbers; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Array Exclusion Operationss
by harishnuti (Beadle) on Jul 09, 2008 at 14:16 UTC |