Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Iterate string like, for(1..5) i.e. $stirng="1..5"; for($string)

by schwern (Scribe)
on Oct 11, 2005 at 06:15 UTC ( #499040=note: print w/replies, xml ) Need Help??

in reply to Iterate string like, for(1..5) i.e. $stirng="1..5"; for($string)

my $range = "2..5,10..15"; # Split on commas my @range = split /,/, $range; # Expand any n..m @range = map { /(\d+)..(\d+)/ ? ($1..$2) : $_ } @range;

Assuming the resulting @range is small (where small is, say, less than 10,000 elements) this will do fine. Error checking is left as an exercise for the reader.

  • Comment on Re: Iterate string like, for(1..5) i.e. $stirng="1..5"; for($string)
  • Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://499040]
[robby_dobby]: Oh, shit -- I was replying to someone, but it wound up here. -_-
robby_dobby is still not used to PM's interface. /o\
[oiskuu]: War. War never changes.
[robby_dobby]: "My cat is a very good mouser" -- that's a great way to identify a Brit among a crowd :-)
thezip looks around to see no one else dancing to Piazzola...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2017-11-17 19:42 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (272 votes). Check out past polls.