in reply to Re: Foreach/While - Why does this run AFTER that?
in thread Foreach/While - Why does this run AFTER that?
Just a few thoughts on your pseudo-code:
my $chunks = $length/ #divided by how ever many chunks you want
This would seem to give you a chunk length rather than a number of chunks, but you are subsequently iterating over $chunks as if it were a number of chunks.
foreach (0 .. $chunks){
...
}
This gives an off-by-one error if $chunks is the number of chunks over which you want to iterate. Either
foreach (0 .. $chunks - 1) { ... }
or
foreach (1 .. $chunks) { ... }
would seem to do a better job (if knowing the chunk index is not an issue).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Foreach/While - Why does this run AFTER that?
by james28909 (Deacon) on Oct 06, 2014 at 23:07 UTC |