Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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?
[LanX]: I know its a cult... and I repent it every time
[LanX]: But cygwin comes with path problems and powershell requires too much learning for me
[LanX]: eshell in emacs is often my resort in development
[LanX]: Thx found a solution! :)
[Eily]: I wrote "your" instead of "you're" :'(
[Eily]: I guess it means that my English is good enough that I make the same mistakes as native speakers though :/
[LanX]: your native tounge is French .... or Quebequois?
[erix]: never mind the natives
[Eily]: French, why?

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2017-03-27 16:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (320 votes). Check out past polls.