I have perl, v5.6.1 built for MSWin32-x86-multi-thread Binary build 638 provided by ActiveState.
I am working on a Perl script where I have declared constants that are used later for comparison purposes. For some reason, I am getting an error that states something along the line of Constant name has invalid characters at script's line 31 (The line right after the use constant clause in the code below). I checked and found out that '_' (underscores) in Constant name is a legit character. I also tried to change '0.00' to just '0' to see if that was the cause but I got the same error. I am not sure what I am doing wrong. Anyone know why the compiler does not like this?
Thanks!
Here is the Code:
use constant {
MIN_NET_DLR => 0.00,
MAX_NET_DLR => 99.99,
MIN_SUM_DLR => 0.00,
MAX_SUM_DLR => 999.99,
MIN_UNITS => 0,
MAX_UNITS => 99,
MIN_SUM_UNITS => 0,
MAX_SUM_UNITS => 999,
PCT_THRES_AO => 1,
PCT_THRES_TRANS_CUST_BI => 20,
PCT_THRES_CUST => 3,
};
PROBLEM:
The problem is that the version of constant provided by perl 5.6.1 does not support hash reference.
SOLUTION:
Use the regular declaration for constants. Hence, the declaration will look as follows:
use constant MIN_NET_DLR => 0.00;
use constant MAX_NET_DLR => 99.99;
use constant MIN_SUM_DLR => 0.00;
use constant MAX_SUM_DLR => 999.99;
use constant MIN_UNITS => 0;
use constant MAX_UNITS => 99;
use constant MIN_SUM_UNITS => 0;
use constant MAX_SUM_UNITS => 999;
use constant PCT_THRES_AO => 1;
use constant PCT_THRES_TRANS_CUST_BI => 20;
use constant PCT_THRES_CUST => 3;
Thanks @leon for the solution as well as others who chimed in with their inputs.
UPDATE: Another (more elegant) solution is to update your Perl version to the one that supports hash reference in declaring constants.