Control Structures

The if statement

if (expression) {         # condition
  __________________;
  __________________;    # do if true
  __________________;
  
}else {
  __________________;
  __________________;    # do if false
  __________________;
}

The unless statement

unless (expression) {     # condition 
  __________________;
  __________________;    # do if false
  __________________;
   
}else {
  __________________;
  __________________;    # do if true
  __________________;
}

Example:

#!/usr/bin/perl

# receive a number from user

print "enter number: ";
my $n = <STDIN>;
chomp ($n);

# make a decision and act accordingly

if ($n > 10) {
  print "large number\n";
}else {
  print "small number\n";
}


Table of Contents.
Previous | Next.