Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: arrays and loop through array

by philipbailey (Chaplain)
on Mar 06, 2011 at 12:33 UTC ( #891674=note: print w/ replies, xml ) Need Help??


in reply to arrays and loop through array

You could use eval, as follows:

#!/usr/bin/perl use warnings; use strict; my $str = "1, 2 ,3, 4,6 -10,11 - 15,16, 17"; $str =~ s/\s+//g; $str =~ s/-/\.\./g; my @arr = eval $str; for (@arr){ my $i = $_; print "==>>> $i\n"; }

You need to be very sure that you have cleaned up arbitrary user input before using eval in this way.


Comment on Re: arrays and loop through array
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2015-07-07 04:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls