If these are constants that may be required for interpolation into strings, etc., consider grouping related constants into a hash and making a hash constant using Const :: Fast . This reduces the pollution of the namespace, allows you to check all constants in a specific group, etc. For example, consider the READYSTATE enumeration values for the IE ReadyState . Instead of creating a separate variable or a separate constant function for each value, you could group them in a hash:
package My::Enum; use strict; use warnings; use Exporter qw( import ); our @EXPORT_OK = qw( %READYSTATE ); use Const::Fast; const our %READYSTATE => ( UNINITIALIZED => 0, LOADING => 1, LOADED => 2, INTERACTIVE => 3, COMPLETE => 4, ); __PACKAGE__; __END__
And then you can intuitively use them, as in:
use strict; use warnings; use My::Enum qw( %READYSTATE ); for my $state (sort { $READYSTATE{$a} <=> $READYSTATE{$b} } keys %READYSTATE) { print "READYSTATE_$state is $READYSTATE{$state}\n"; }
See also Neil Bower's excellent CPAN module for constants .
Sinan รnรผr
source share