Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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 ( #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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://778339]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2023-01-28 10:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?