Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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 ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://499040]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-19 22:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found