Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
In larger programs, I like to guard against typos in hash keys (when the keys are a known, fixed set) using Hash::Util's lock_keys, or I'll retrofit a large program with this module for the same purpose.
Is there something like this for scalars? I.e. something that lets me restrict the value of a scalar to a set of allowed values? (I've searched, but not found anything yet.) Something like this:
tie my $state, 'Scalar::Restrict', qw/ idle waiting active /; # or maybe lock_scalar my $state, qw/ idle waiting active /; # $state may now only be "idle", "waiting", or "active"
Thanks in advance for your thoughts.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Restricting a scalar to certain values
by tobyink (Canon) on Jun 20, 2013 at 08:56 UTC | |
|
Re: Restricting a scalar to certain values
by jakeease (Friar) on Jun 20, 2013 at 08:14 UTC | |
|
Re: Restricting a scalar to certain values
by Anonymous Monk on Jun 20, 2013 at 08:31 UTC | |
|
Re: Restricting a scalar to certain values
by Anonymous Monk on Jun 20, 2013 at 08:56 UTC | |
|
Re: Restricting a scalar to certain values
by locked_user sundialsvc4 (Abbot) on Jun 21, 2013 at 12:55 UTC |