in reply to Re^2: Specifying a range through a variable
in thread Specifying a range through a variable

How to do convert the string "1..10" to mean the range 1 through to 10

A bit kludgey:
use warnings; my $range = "1..10"; my @wanted = range($range); print "@wanted\n"; sub range { my @t = split /\.\./, $_[0]; return ($t[0] .. $t[1]); }
Update: To return first and last values, obviously:
sub range { my @t = split /\.\./, $_[0]; return ($t[0], $t[1]); }
Cheers,
Rob

Replies are listed 'Best First'.
Re^4: Specifying a range through a variable
by dragonchild (Archbishop) on Sep 19, 2008 at 13:40 UTC
    my @t = $_[0] =~ /^\s*(-?\d+)\s*\.\s*\.(\s*\.)?\s*(-?\d+)\s*$/;
    Be as strict as possible in what you accept. That way, errors are caught as early as possible.

    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?