Skip to main content

Timeline for answer to Does Perl have an enumeration type? by Ronald Blaschke

Current License: CC BY-SA 3.0

Post Revisions

13 events
when toggle format what by license comment
Aug 3, 2017 at 9:52 comment added Nagev I still prefer this answer because it works out-of-the-box and in my opinion, still very simple. Just to add that enumeration would normally use integers to represent the different values, e.g. HOME => 0. I wouldn't use strings unless I need to actually print the names.
S Apr 7, 2014 at 16:20 history suggested titanofold CC BY-SA 3.0
Link to MetaCPAN
Apr 7, 2014 at 16:18 review Suggested edits
S Apr 7, 2014 at 16:20
Jun 12, 2011 at 0:40 comment added Yevgeny Simkin Not that it really matters, but I would seriously consider moving the green checkmark to Nathan's answer. I just installed the enum module and it works perfectly.
Feb 25, 2010 at 16:26 history edited Brad Gilbert CC BY-SA 2.5
Added links
Jan 26, 2010 at 7:32 comment added Nathan Fellman This is actually inaccurate as later version of Perl do. Look here stackoverflow.com/questions/473666/…
Jan 19, 2010 at 11:36 comment added Ronald Blaschke Your examples don't match up ;-), but yes, the current implementation does. See section TECHNICAL NOTES in perldoc constant. constant also does some name checking. For example, starting with double underscores is disallowed, and names like 'BEGIN' cause a warning (with 'use warnings') because they might be confusing. For details have a look at the implementation by calling 'perldoc -m constant'.
Jan 18, 2010 at 18:18 comment added Phill Pafford Just for clarification sub HOME () {'home'} and use constant { HOME => 'Home', WORK => 'Work', MOBILE => 'Mobile', }; are the same? the later generates (Behind the scene) the code?
Jun 25, 2009 at 10:13 comment added Cheok Yan Cheng When you have a subroutine which take in Phone::Type enum as argument, how do you perform dynamic checking on the subroutine argument is Phone::Type type enum, not string, not number...
Feb 4, 2009 at 23:24 vote accept cowgod
Jan 30, 2009 at 17:53 history edited Ronald Blaschke CC BY-SA 2.5
Added prototype to sub HOME (many thanks to Hynek -Pichi- Vychodil for mentioning this)
Jan 26, 2009 at 13:21 comment added Hynek -Pichi- Vychodil For strictness, there is sub HOME () {'home'} made behind scene.
Jan 23, 2009 at 19:52 history answered Ronald Blaschke CC BY-SA 2.5