Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: regex to an array , is there a better way to do this

by moritz (Cardinal)
on Jul 08, 2009 at 16:42 UTC ( [id://778339] : note . print w/replies, xml ) Need Help??


in reply to regex to an array , is there a better way to do this

Your input happens to be valid Perl syntax, so if you know exactly that your input is in this format (and contains no evil things), you can simply write:
my @array = eval $number;

Or you could simplify your code a bit:

for (my $i=$1;$i<=$2;$i++){ push @arraydigit, $i; }

Can be written shorter and clearer as

push @array, $1..$2;

There's really no point in having @array and @arraydigit separate.