in reply to How to create loop in perl dynamically
#!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 | |
by grizzley (Chaplain) on Sep 26, 2012 at 14:40 UTC |