So what does your new code look like?
I personally believe that I should first warn any newbie possibly reading this post in the future that its content is deliberately humorous in a sarcastic way. So please don't even think of picking up the code shown here and use it in anything serious...
I... huh... personally believe that with 5.10's new features we can eventually implement in Perl the FOR-CASE paradigm:
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
for my $count (0..4) {
given ($count) {
when (0) { say "Whoa, it's $count" }
when (1) { say "Then it becomes $count" }
when (2) { say "Then, $count" }
when (3) { say "Only to further increase to $count" }
when (4) { say "And eventualy stop at $count" }
}
}
Of course, we may avoid the inner given:
But we care about efficiency all the time, don't we? Furthermore, this may begin to give a wrong output the day a number which is equal to 0 will also be equal to 1, for example.
Last, prior to 5.10, one of the standard answers for those in search of a switch statement was to use a dispatch table instead, so for backwards compatibility reasons, let's see how it may look like:
Or at most, using closures:
Anyway, with 5.10 it's much slicker!
|