#!/usr/bin/perl

use strict;



print"\nUndef var\n";
#evaluates to False
#you may set a variable to undefined using undef() ... it will eval to false!
my $undef_value = undef();
_test_truth_w_defined_subroutine($undef_value);
_test_truth_w_value($undef_value);

print"\nChar string\n";
#scalar has something set to it, evaluates to TRUE
my $chars = "adfghdas";
_test_truth_w_defined_subroutine($chars);
_test_truth_w_value($chars);

#we can undef any variable...it will not eval to FALSE
print "\nundef the above char string\n";
$chars = undef;
_test_truth_w_defined_subroutine($chars);
_test_truth_w_value($chars);

#what about double quoted null variables?
print "\n double quote empty string\n";
my $dq_var = "";
_test_truth_w_defined_subroutine($dq_var);
_test_truth_w_value($dq_var);

#and finally, and uninitialized variable?
print "\n Uninitialized\n";
my $ui_var;
_test_truth_w_defined_subroutine($ui_var);
_test_truth_w_value($ui_var);

#what about single quoted null variables?
print "\nsingle quote empty string\n";
my $sq_var = '';
_test_truth_w_defined_subroutine($sq_var);
_test_truth_w_value($sq_var);


print"\npositive number";
#any non zero number is true
my $pos_num = "100";
_test_truth_w_defined_subroutine($pos_num);
_test_truth_w_value($pos_num);

print"\nnegative number";
#a negative number is a true value
my $neg_num = "-4";
_test_truth_w_defined_subroutine($neg_num);
_test_truth_w_value($neg_num);

##notice how the next two behave differently depending if the value or the result of the defined method is used...
print"\nZero!";
my $zero = 0;
_test_truth_w_defined_subroutine($zero);
_test_truth_w_value($zero);

print"\ndouble quoted zero";
my $quot_zero = "0";
_test_truth_w_defined_subroutine($quot_zero);
_test_truth_w_value($quot_zero);





sub _test_truth_w_defined_subroutine {
    my ($var) = @_;

    print "Testing \-$var\- w/defined subroutine:\n";
    if (defined($var)) {
	print "\t IS true!!!\n";
    } else {
	print "\t is NOT true!!!\n";
    }
}




sub _test_truth_w_value {
 my ($var) = @_;

    print "Testing \-$var\- using raw value:\n";
    if ($var) {
	print "\t IS true!!!\n";
    } else {
	print "\t is NOT true!!!\n";
    }

}

