in reply to Specifying a range of indices via the command line

I think this catches all the same things as your code though the error message maybe different or less detailed:

sub range_to_list { my( $max, $range ) = @_; my( $lo, $sep, $hi ) = $range =~ m[^(\d+)?(?:(-)(\d*))?$] or die " +Invalid range:$range\n"; $lo ||= 0; $hi ||= $sep ? $max : $lo; $_ > $max and die "$_ out of range\n" for $lo, $hi; return $lo .. $hi; }

Output from your tests:

C:\test>junk61 maxind=10 rstr:x:...exc:Invalid range:x rstr:1-2-3:...exc:Invalid range:1-2-3 rstr:0:...ret:0: rstr:10:...ret:10: rstr:11:...exc:11 out of range rstr:4:...ret:4: rstr:4-6:...ret:4 5 6: rstr:7-:...ret:7 8 9 10: rstr:-2:...ret:0 1 2: rstr:-10:...ret:0 1 2 3 4 5 6 7 8 9 10: rstr:-11:...exc:11 out of range rstr:-0:...ret:0 1 2 3 4 5 6 7 8 9 10: rstr:10-:...ret:10: rstr:11-:...exc:11 out of range apples :one::two::three:

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked