Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
The Perl5 CPAN module 'enum'
Perl
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
t
Changes
INSTALL
MANIFEST
Makefile.PL
README

README

The 'enum' module for Perl

This module is used to efine a set of symbolic constants with ordered numeric values
similar to enum types in the C programming language.

Now capable of creating creating ordered bitmask constants as well. See
the BITMASKS section for details.

What are they good for? Typical uses would be for giving mnemonic names
to indexes of arrays. Such arrays might be a list of months, days, or a
return value index from a function such as localtime():

  use enum qw(
      :Months_=0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
      :Days_=0   Sun Mon Tue Wed Thu Fri Sat
      :LC_=0     Sec Min Hour MDay Mon Year WDay YDay Isdst
  );

  if ((localtime)[LC_Mon] == Months_Jan) {
      print "It's January!\n";
  }
  if ((localtime)[LC_WDay] == Days_Fri) {
      print "It's Friday!\n";
  }

This not only reads easier, but can also be typo-checked at compile time
when run under use strict. That is, if you misspell Days_Fri as
Days_Fry, you'll generate a compile error.

Something went wrong with that request. Please try again.