June 2005
Beginner
480 pages
10h 31m
English
| Q1: | I'm familiar with another programming language, C, which has a switch (or case) statement. Where is Perl's switch statement? |
| A1: | Perl doesn't have one! Perl provides such a variety of tests that figuring out the best syntax for a switch statement is nightmarish. The simplest way to emulate a switch statement is as follows:
if ($variable_to_test == $value1) { statement1; } elsif ($variable_to_test == $value2) { statement2; } else { default_statement; } The online syntax manual page—which you can view by typing perldoc perlsyn at a command prompt—contains many clever examples of how to emulate a switch statement in Perl, some with very switch-like syntax. |
| Q2: | How many for (while, if) blocks can I nest inside each other? |
| A2: | As many as you ... |
Read now
Unlock full access