DrWhy has asked for the wisdom of the Perl Monks concerning the following question:
Where $count is acting as a sempaphore.$count = 2; foreach (0..2) {} continue {print $_,"\n" if $count--}
I'm wondering if there is some way to do this without the semaphore. For example, is there some CPAN module that implements a thing like continue that doesn't fire off after the last loop iteration? Or maybe some algorithmic trick I haven't though of. This needs to work with a foreach where I'm not keeping any explicit loop counter (unlike the baby example above).
"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: I need a different continue
by diotalevi (Canon) on Dec 09, 2004 at 18:18 UTC | |
by Roy Johnson (Monsignor) on Dec 09, 2004 at 18:26 UTC | |
|
Re: I need a different continue
by Joost (Canon) on Dec 09, 2004 at 18:36 UTC | |
|
Re: I need a different continue
by Roy Johnson (Monsignor) on Dec 09, 2004 at 18:50 UTC | |
|
Re: I need a different continue
by hmerrill (Friar) on Dec 09, 2004 at 18:19 UTC | |
by DrWhy (Chaplain) on Dec 09, 2004 at 18:48 UTC | |
by Jenda (Abbot) on Dec 10, 2004 at 16:43 UTC | |
by DrWhy (Chaplain) on Dec 16, 2004 at 19:23 UTC | |
by Jenda (Abbot) on Dec 17, 2004 at 17:05 UTC | |
|
Re: I need a different continue
by gaal (Parson) on Dec 09, 2004 at 18:27 UTC | |
|
Re: I need a different continue
by Jenda (Abbot) on Dec 10, 2004 at 17:37 UTC |