Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How to create loop in perl dynamically

by grizzley (Chaplain)
on Sep 26, 2012 at 13:25 UTC ( #995767=note: print w/replies, xml ) Need Help??


in reply to How to create loop in perl dynamically

I would create array containing max values for each loop and iterate over array.
#!perl -l @maxvalues = (2, 5, 3); $input = 3; my @ids = (0) x $input; # assuming all loops start with 0 while(!$end) { # do something print "[@ids]"; # increase values starting from end of ids array $index = $#ids; while(1) { $ids[$index]++; if($ids[$index]<=$maxvalues[$index]) { last } else { # we reached limit on loop pointed by $index $ids[$index] = 0; $index--; if($index<0) # check stop condition { $end = 1 } } } }

Replies are listed 'Best First'.
Re^2: How to create loop in perl dynamically
by adithi (Initiate) on Sep 26, 2012 at 14:09 UTC
    Thank u. But I didnt the logic used here.
      Then spend some time analyzing it, understanding the code you want to use is very important. If you won't get it (actually even if you will) - use module, as advised here: Re: How to create loop in perl dynamically

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995767]
help
Chatterbox?
[shmem]: the biker stopped the machine at the table and took off his helmet.
[shmem]: long white hair, long beard the same, then he proceeded to get off the bike
[shmem]: saying "biking itself isn't that much, but getting up and down - hell!"
[shmem]: up and down: on and off the bike, of course

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2017-06-25 20:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (570 votes). Check out past polls.