I need to use constants that are (a) usually numeric, and (b) often included in text sent to the user. Of the WTDI I'm sure there are many, but I've found two, and I hope there are better ones.
Method numero uno uses use constant. An advantages is that everything looks like a constant; a disadvantage is that the dot construct looks kind of ugly.
use constant MIN_CHAR => scalar 1; use constant MAX_CHAR => scalar 12; print 'x '.MIN_CHAR.'-'.MAX_CHAR.' x';
Method numero two uses a hash. An advantage is that there's no dot concatenation; a disadvantage is that they don't look much like constants anymore.
my %constants = ( min_char => 1, max_char => 12 ); print "x $constants{'min_char'}-$constants{'max_char'} x";
Left to my own devices, I'd use the first. The dots are ugly, but at least I'm using constants like constants. Does anyone have a better method?
Thanks
--
man with no legs, inc.
In reply to Use constant vs. hashes by legLess
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |