#!/usr/bin/perl -w

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #  
# final_2.pl
# 
# assignment: explain what a specific subroutine does and
#             why it behaves differently in two cases
#           
#
# Author: John Berry
# Date: 12/11/03
#
# Version 0.01
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #  


# The key to what is happening lies in the 'and' keyword.  It returns
# the "logical conjunction of the two surrounding expressions."(1)  The
# keyword 'and' is also a lazy operator, so if the left side evaluates
# false, the right side won't be evaluated.
#
# What happens here is that a number is passed to the doit subroutine.  The
# first operation that happens is the 'shift'.  This returns the number
# passed to the subroutine.  If that number does not evaluate to false (i.e.,
# is NOT zero) the 'and' keyword allows the print statement to run.  If the
# number does evaluate to false (i.e, IS zero) the print statement does not
# happen, which is why in the first case we see something print and in the
# second, we do not.

use strict;

doit(24);
doit(1);
doit(0);

sub doit {
  our $x = shift and print "x is $x\n";
  print "$x\n";
}
