Please send questions to st10@humboldt.edu .
#!/usr/bin/perl -w

#######################################################
# lect03_my1
#
# using lexical variables 
# 
# modified by Sharon Tuttle from "Learning Perl",
#    by Schartz and Phoenix
#
# last modified: 9-6-04
#######################################################

#-------------------------------------------------------
# printing a greeting, using a lexical variable...
#    ...and perhaps getting a surprise!
#-------------------------------------------------------

sub greeter2
{
    my($cust_num);    # a new copy EVERY time subroutine is 
                      #    called...
    $cust_num += 1;

    print "\n***** Welcome to Perl-mart! *****\n";
    print "Hello, you are customer #$cust_num today!\n";
    print "*********************************\n\n";
}

# call greeter2 several times, see what happens

&greeter2;
&greeter2();

# any $cust_num here is DIFFERENT from that inside $greeter2

print "\$cust_num: $cust_num\n";
$cust_num = 53;
print "changed \$cust_num to: $cust_num\n";

# ...and inside greeter2?

&greeter2();

print "the global \$cust_num is still: $cust_num\n";

# end of lect03_my1