GlitchMr has asked for the wisdom of the Perl Monks concerning the following question:
After you will type at least use 5.010 you can use given statement. It allows you to use when inside it, but for/foreach also allows it. I would like to know why Perl has given when for can be used for this same thing (at least I think so).
For background, in this example, both code samples are equivalent.
for ($value) { when (1) { say "One!" } when (2) { say "Two!" } default { say "Something!" } }
given ($value) { when (1) { say "One!" } when (2) { say "Two!" } default { say "Something!" } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: given and for
by moritz (Cardinal) on Aug 21, 2012 at 09:02 UTC | |
by Monk::Thomas (Friar) on Aug 24, 2012 at 09:20 UTC | |
|
Re: given and for
by Arunbear (Prior) on Aug 21, 2012 at 09:41 UTC | |
|
Re: given and for
by MidLifeXis (Monsignor) on Aug 21, 2012 at 12:58 UTC | |
|
Re: given and for
by 2teez (Vicar) on Aug 21, 2012 at 10:13 UTC | |
by GlitchMr (Sexton) on Aug 21, 2012 at 10:17 UTC |