NAME
enum::hash - create a hash of 'enum's, with the same interface as enum.pm
SYNOPSIS
use enum::hash 'enum';
%days = enum (qw/ Sun Mon Tue Wed Thu Fri Sat /);
# $enum{Sun} == 0, $enum{Mon} == 1, etc
%random = enum (qw/ Forty=40 FortyOne Five=5 Six Seven /);
# Yes, you can change the start indexes at any time as in C
%count = enum (qw/ :Prefix_ One Two Three /);
## Creates $enum{Prefix_One}, $enum{Prefix_Two}, $enum{Prefix_Three}
%letters = enum (qw/ :Letters_ A..Z /);
## Creates $enum{Letters_A}, $enum{Letters_B}, $enum{Letters_C}, ...
%enum = 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
:Letters_=20 A..Z
/);
## Prefixes can be changed mid list and can have index changes too
DESCRIPTION
Provides the same interface as the enum module, but returns the values as a list, instead of creating symbolic constants.
By default, the 'index' values start at zero, increasing by one for each pair. You can change the index at any time by passing it after an equals sign.
%enum = enum ('one=1', 'two', 'three', 'ten=10', 'eleven');
# outputs
one => 1
two => 2
three => 3
ten => 10
eleven => 11
You can set a prefix that will be prepended to each key name, by passing an item beginning with :
. You can remove any prefix by passing an item containing only :
.
%enum = enum (qw/
:prefix_ 1 2
: 3 4
/);
# outputs
prefix_1 => 1
prefix_2 => 2
3 => 3
4 => 4
A prefix declaration can also set the index value.
%enum = enum (qw/
:day=1 One Two
/);
# outputs
dayOne => 1
dayTwo => 2
Any items containing ..
will be treated as a list range:
%enum = enum ('1..5');
# is equivalent to
%enum = enum (1 .. 5);
enum::hash is less restrictive on key names than enum is: a key name can start with a character other than [a-zA-Z]
.
EXPORT
Nothing by default.
enum
subroutine, on request.
INCOMPATABILITY
Does not support enum's BITMASK function, and does not support any type of label before the :
prefix identifier.
# Not Supported
use enum qw(
BITMASK:BITS_ FOO BAR CAT DOG
ENUM: FALSE TRUE
ENUM: NO YES
BITMASK: ONE TWO FOUR EIGHT SIX_TEEN
);
SUPPORT / BUGS
Submit to the CPAN bugtracker http://rt.cpan.org.
SEE ALSO
enum by Byron Brummer (see "COPYRIGHT AND LICENSE").
AUTHOR
Carl Franks
CREDITS
Byron Brummer, author of enum (see "COPYRIGHT AND LICENSE").
COPYRIGHT AND LICENSE
Copyright 2005, Carl Franks. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself (perlgpl, perlartistic).
Contains code and documentation examples copied from the enum distribution, by Byron Brummer.
Derived from the original enum cpan distribution,
Copyright 1998 (c) Byron Brummer. Copyright 1998 (c) OMIX, Inc.
Permission to use, modify, and redistribute this module granted under the
same terms as Perl.