How about this?

use strict; use warnings; use feature 'say'; @ARGV or die 'No range specified'; # Check if the range was specified correctly. # This will filter out negative numbers as well. $ARGV[0] =~ /\A(?:\d+)?-(?:\d+)?\Z/ or die 'Invalid range'; my @commands = qw(zero one two three four); # In case one of the values was not specified it will become an empty +string my ($start, $end) = split '-', $ARGV[0]; # Since an empty string evaluates to false we can assign default value +s like this $start = 0 unless $start; $end = $#commands unless $end; # Negative indices are filtered out by the first regex so we only need + to check if the index is not too big. die "$start is out of range" unless $start < @commands; die "$end is out of range" unless $end < @commands; # The range is sure to be valid now so we can simply use .. to generat +e a list foreach my $index ($start .. $end) { say $commands[$index]; }

In reply to Re: Specifying a range of indices via the command line by kroach
in thread Specifying a range of indices via the command line by eyepopslikeamosquito

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.