May 2002
Beginner
704 pages
16h 37m
English
Conditionals are used to execute different bits of code based on the value of a given test. If the test is true, a block of code is executed; if the test is false, either execution continues to the next part of the script, or a different block of code is executed. Unlike loops, each block is executed only once.
The most common form of conditional is the if, and its variant forms if…else and if…elsif. As you've seen, the if statement looks like this:
if ( test ) {
# statements
}
The test is any expression, evaluated in a boolean scalar context for its truth value. Remember that everything except "", 0, and undef is considered true. If the test is true, the block is executed. If it's false, nothing happens ...