Databases Reference
In-Depth Information
print "The weather is fine.\n";
}
or if either condition is met:
# Boolean OR
if( ($temperature < 18) || ($temperature > 35) )
{
print "The weather isn't fine.\n";
}
or if a condition is not met:
# Boolean NOT (negating the condition)
if( !($temperature < 18) )
{
print "The weather isn't cold.\n";
}
You will often see the Boolean operators written in the long form: and , or , and not . For
example, you can write:
# Symbolic and long form of Boolean expressions
my $value=74;
# A combined expression...
if( ($value > 80) || ( ($value < 75) && ! ($value == 73)) )
{
print "The value is greater than 80 or less than 75, but is not 73\n";
}
as:
# ...and the equivalent in long form
if( ($value > 80) or ( ($value < 75) and not ($value == 73)) )
{
print "The value is greater than 80 or less than 75, but is not 73\n";
}
The long forms and and or aren't in fact identical to their symbolic counterparts && and
|| . Perl assigns the long forms a very low operator precedence; as we noted earlier in
“Operator precedence,” it's best to use parentheses to express the precedence you want.
Reading Input from the Command Line and from Files
Consider our sample animals script; the names of the animals and the numbers of each
are hardcoded into the program. A better solution is to allow the program to use values
provided by the user from the command line or from a file.
 
Search WWH ::




Custom Search