in reply to RE: My views on pseudohashes
in thread My views on pseudohashes
and then use the resulting object, I can still autovivify member variables, leading to a whole raft of typo problems:package hashobject; sub new { my ($class) = @_; $class = ref($class) || $class; my $self = {}; $self->{variable} = 'foo'; return(bless($self, $class)); }
If we move to a pseudohash, the object looks like this:my $obj = new hashobject; $obj->{variablee} = 'bar'; # TYPO... print $obj->{variable}; # Prints 'foo'
And then (mis)use the object in the same way:package pseudohashobject; use fields qw(variable); sub new { my ($class) = @_; $class = ref($class) || $class; my $self = bless([\%FIELDS], $class]); $self->{variable} = 'foo'; return($self); }
the typo actually causes a runtime exception! This makes very hard to find bugs easy to find, and hence is a good thing (tm). I would suggest looking into Damien Conway's Object Oriented Perl (Manning) for more information. I would almost rate this book as more important than the Camel!my $obj = new pseudohashobject; $obj->{variablee} = 'bar'; # TYPO print $obj->{variable};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: RE: RE: My views on pseudohashes
by sparky8342 (Acolyte) on May 23, 2001 at 20:34 UTC | |
by chipmunk (Parson) on May 23, 2001 at 23:35 UTC |