#!/usr/bin/perl -w

use strict;


#main is defined below.  this is the only 'call' made by this script.
#I use main as a way to keep my executing code in order

#perl variables are generally lowercase, but for variables which are accesible
#to the whole script, upper case is used.
##The var GLOBAL_VAR is initialized in this broadest scope of the program
##it is not enclosed in {}, so it is accesible to any code 'below' it 
##aka- any code which is at this level and enclosed in brackets
my $GLOBAL_VAR = "some important info";

main();

my $OTHER_GLOBAL_VAR = "more important info";

#but another call to main after this
main();

sub main {


    #We can use the global variable because it was defined above the scope of
    #this function
    print "Can we see the variable defined \'above\' this method? \"$GLOBAL_VAR\"\n";

    #note how this variable is 'empty' until it is initialized, but is accesible
    #when we make a main call after the variable has been initialized.
    #This is VERY odd behavior... use the -w flag to help identify these situations
    print "What about the variable defined below the main() call above! .. \"$OTHER_GLOBAL_VAR\"\n\n\n";

    #in deeper code blocks in this subroutine the global variables are still 
    #accesible.
    if (1 eq 1) {
	print "\tglobal1: $GLOBAL_VAR\n\tglobal2: $OTHER_GLOBAL_VAR\n\n";
    }

}

