README
1The 'enum' module for Perl
2
3This module is used to efine a set of symbolic constants with ordered numeric values
4similar to enum types in the C programming language.
5
6Now capable of creating creating ordered bitmask constants as well. See
7the BITMASKS section for details.
8
9What are they good for? Typical uses would be for giving mnemonic names
10to indexes of arrays. Such arrays might be a list of months, days, or a
11return value index from a function such as localtime():
12
13 use enum qw(
14 :Months_=0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
15 :Days_=0 Sun Mon Tue Wed Thu Fri Sat
16 :LC_=0 Sec Min Hour MDay Mon Year WDay YDay Isdst
17 );
18
19 if ((localtime)[LC_Mon] == Months_Jan) {
20 print "It's January!\n";
21 }
22 if ((localtime)[LC_WDay] == Days_Fri) {
23 print "It's Friday!\n";
24 }
25
26This not only reads easier, but can also be typo-checked at compile time
27when run under use strict. That is, if you misspell Days_Fri as
28Days_Fry, you'll generate a compile error.
29
30