* Luinrandir Hernsen <[EMAIL PROTECTED]> [2004-01-23T09:38:12] > Hallo everyone and thank you for your previous help > > in basic the code would be > Select Case > ... > end select > > how is this done in perl?
Well, this is a common question. In fact, it's a frequently asked one
with an entry in the perlfaq. This kind of construct is called, in many
languages, a switch. You can see the FAQ's answer by running "perldoc
-q switch" or by looking for the switch/case question in perlfaq7.
Your example was specific, so I can give a specific answer or two:
for (1 .. 100) {
unless ($_ % 10) {
print "divisible by ten\n";
}
}
That's about what you said, right? For every number from 1 to 100, do
something at the ten's. Of course, someone more familiar with C (or
with the syntax of 'for') might say:
for (my $i = 1; $i <= 100; $i+=10) {
print "$i is divisible by ten!\n";
}
This skips a condition, incrementing $i by ten every time.
See, Perl was designed knowing that there are a whole lot of ways to use
a switch, and a whole lot of ways one might implement it specifically.
So, rather than canonize one, a single "switch" statement is left out.
The best thing to do is figure out how to solve the problem the best
way.
There does exist a module called Switch that will give you a switch/case
statement, but it's not really for production use. It's a neat idea,
but isn't ready for prime time.
Does that answer your question?
--
rjbs
pgp00000.pgp
Description: PGP signature
