Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neilb/enum
The Perl5 CPAN module 'enum'
https://github.com/neilb/enum
Last synced: 3 months ago
JSON representation
The Perl5 CPAN module 'enum'
- Host: GitHub
- URL: https://github.com/neilb/enum
- Owner: neilb
- Created: 2013-08-24T10:36:17.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2021-08-08T22:22:05.000Z (over 3 years ago)
- Last Synced: 2024-05-22T00:03:34.075Z (8 months ago)
- Language: Perl
- Size: 26.4 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README
- Changelog: Changes
Awesome Lists containing this project
README
The 'enum' module for Perl
This module is used to define 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.