I have this code and having matched the input, I want it split into two separate variables. The input is in the form of a range (e.g: 1-10) and is written in perl.

Here is the code: [ if($pr=~m/^([0-9]+)\s*[-]\s*([0-9]+)$/){ print "Match"; } else { print "Not a match"; } ]

Thanks.

To rephrase properly, I have this code and having matched the input, I want it split into two separate variables. The input is in the form of a range (e.g: 1-10) and is written in perl.

Here is the code:

sub regX()
{
print "Enter port range (e.g 1-2): "; chomp($pr=<STDIN>);
if($pr=~m/^([0-9]+)\s*[-]\s*([0-9]+)$/){ print "Match"; }
else { print "Not a match"; }
}

Thanks.

Hi all,

This is a perl script. I have this input that I intend to split into multiple variables, however the variables $1 and $2 work for a limited number of inputs. Please run code and see first then provide an advice. Thanks for your suggestions.

sub regX()
{
print "Enter numbers with ',' as delinmeter (e.g.: 1,2,3,...): ";
chomp($pr=<STDIN>);
if($pr=~m/^(([0-9]+)\s*[,]\s*([0-9]+)*)+$/)
{
#print multiple variables up to n inputs
}
else { print "Unmatched entry"; }
}

Why don't you just split them on the "," into an array?

$count=(@array)=split(/\,/,$pr);

Your regX is not going to work the way that you wish for it to. When I ran the code I input "1,2,3" and got "1 2,3" in $1.

Why don't you just split them on the "," into an array?

$count=(@array)=split(/\,/,$pr);

Your regX is not going to work the way that you wish for it to. When I ran the code I input "1,2,3" and got "1 2,3" in $1.

True statement mitchems...I'll try that. Thanks for the quick response.

This question has already been answered. Start a new discussion instead.