in reply to Array Exclusion Operationss

Add the following to the top:
use strict; use warnings FATAL => 'all';
Fix all the problems that arise. Your problems will be much clearer now.

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; }

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^2: Array Exclusion Operationss
by harishnuti (Beadle) on Jul 09, 2008 at 14:16 UTC

    dragonchild, you know what, your solution is excellent, i should have used map and hash in this way , i got what i intended