in reply to Should I use Fields, InsideOuts, or Properties?
A couple of options:
- Use blessed arrays and constants for your objects. Smaller, faster and safer.
- Initialise your blessed hashes with the required fields and set them readonly manually.
use Internals qw(SetReadOnly);; $fred = bless {},'fred';; @$fred{ qw[ jack john bill ] } = ();; SetReadOnly $fred;; print Dumper $fred;; $VAR1 = bless( { 'john' => undef, 'jack' => undef, 'bill' => undef }, 'fred' ); $fred->{bill} = 3;; print Dumper $fred;; $VAR1 = bless( { 'john' => undef, 'jack' => undef, 'bill' => 3 }, 'fred' ); $fred->{derf} = 'error';; Attempt to access disallowed key 'derf' in a restricted hash at (eval +11) line 1, <STDIN> line 9. print Dumper $fred;; $VAR1 = bless( { 'john' => undef, 'jack' => undef, 'bill' => 3 }, 'fred' );
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Should I use Fields, InsideOuts, or Properties?
by nothingmuch (Priest) on Jul 06, 2005 at 15:31 UTC | |
Re^2: Should I use Fields, InsideOuts, or Properties?
by tphyahoo (Vicar) on Jul 06, 2005 at 11:27 UTC | |
by BrowserUk (Patriarch) on Jul 06, 2005 at 12:01 UTC |
In Section
Seekers of Perl Wisdom