Sometimes based on some condition a piece of code has to be executed or not. Example 5-9. examples/scalars/if_conditional.pl #!/usr/bin/perl
use strict;
use warnings;
print "First number: ";
my $x = <STDIN>;
chomp $x;
print "Second number: ";
my $y = <STDIN>;
chomp $y;
if ($y == 0) {
print "Cannot divide by zero\n";
} else {
my $z = $x / $y;
print "The result is $z\n";
}
If you are interested in on-site trainings by the author, please
contact me directly.
|