• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

lib/H27-Oct-2015-352133

t/H27-Oct-2015-200160

ChangesH A D27-Oct-20153.8 KiB11287

INSTALLH A D13-May-1999205 97

MANIFESTH A D27-Oct-2015294 1413

META.jsonH A D27-Oct-20151.1 KiB5352

META.ymlH A D27-Oct-2015600 2928

Makefile.PLH A D25-Jan-20141,011 4131

READMEH A D27-Aug-20131,002 3022

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