Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2014-07-12 06:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (238 votes), past polls