use constant
{
MY_CONSTANT1 => 1,
MY_CONSTANT2 => 2,
MY_CONSTANT3 => 3,
MY_CONSTANT4 => 4
};
sub useConstants
{
#able to use constants fine in here...
my $var = MY_CONSTANT4;
print "$var\n"; #outputs '4'
}
1;
####
#!/usr/bin/perl
#use strict; # If I uncomment this line it won't compile because it claims MY_CONSTANT3 is a bareword and not a constant.
require "constants.pl";
#if I call useConstants this sub can use them just fine.
useConstants();
#However if I try to use a constant that should've been defined in constants.pl here it won't work!
my $var = MY_CONSTANT3;
print "$var\n"; #outputs 'MY_CONSTANT3' !! Why won't it output '3'?
exit 1;
####
me@mybox:/test
>perl main.pl
4
MY_CONSTANT3
me@mybox:/test
>