in reply to Matching data against non-consecutive range
Update: Fixed bugs# Zone 8 my $z8 = "10-374,376-379,382-385,388-499,530-534,541-543,618,619,700-7 +04,707-709"; my $num = "375"; print "Found it!\n" if in_range($z8, $num); #$num =~/[$z8]/; sub in_range{ my $numbers = shift; my $num = shift; my @ranges = split ',', $numbers; foreach my $r (@ranges){ if (my ($small, $big) = $r =~ /^(\d+)-(\d+)$/){ return 1 if $small <= $num and $big >= $num; } elsif( my ($n) = $r =~ /^(\d+)$/){ return 1 if $n == $num; } else{ die 'Oh noo:-('; } } return 0; }
|
|---|