在Perl中,条件语句使用 if、elsif 和 else 关键字来实现。以下是一些示例:
my $num = 10;
if ($num > 5) {
print "Number is greater than 5\n";
}
my $num = 3;
if ($num > 5) {
print "Number is greater than 5\n";
} else {
print "Number is less than or equal to 5\n";
}
my $num = 5;
if ($num > 5) {
print "Number is greater than 5\n";
} elsif ($num < 5) {
print "Number is less than 5\n";
} else {
print "Number is equal to 5\n";
}
my $num = 6;
unless ($num > 5) {
print "Number is less than or equal to 5\n";
}
在这些示例中,根据条件的结果,会执行相应的代码块。可以根据具体的需求选择合适的条件语句来实现逻辑控制。