No, there is no built-in enum construct. Perl doesn't do a lot of strong typing, so I think that really a little is needed.
In my opinion, the Readonly used Readonly durable.
There is also a more traditional constant pragma.
use constant { HOME => 'Home', WORK => 'Work', MOBILE => 'Mobile', }; $phone_number->{type} = HOME;
Behind the scenes, he sets up a function for each constant that returns a value, for example.
sub HOME () { 'Home' }
I would stick with Readonly if you don't want to use this property, for example:
package Phone::Type; use constant { HOME => 'Home', #... }; package main; print Phone::Type->HOME, "\n";
Ronald Blaschke Jan 23 '09 at 19:52 2009-01-23 19:52
source share