http://www.perlmonks.org?node_id=862431


in reply to Re: Help with cause of "Modification of a read-only value attempted at ..."
in thread Help with cause of "Modification of a read-only value attempted at ..."

package configthing; use strict; use Cwd 'getcwd'; use File::Basename; use fields qw( # snipped for brevity... ); our %DEFAULTS = ( # snipped for brevity... ); 1; sub new { my $this = shift; unless (ref $this) { $this = fields::new($this); } # properties (keys in the pseudohash) we set when an # object is initialized $this->{pname} = basename($0); $this->{pdir} = dirname($0); if ( exists($ENV{'TERM'}) && '' ne $ENV{'TERM'} ) { $this->{is_interactive} = 1; } else { $this->{is_interactive} = 0; } # define empty values for all known configuration keys our %FIELDS; foreach my $k ( keys(%FIELDS) ) { $this->{$k} = '' unless defined($this->{$k}); } # initialize default values our %DEFAULTS; foreach my $k ( keys(%DEFAULTS) ) { $this->{$k} = _expand_value($this, $DEFAULTS{$k}); } return $this; }

doh! I'm mising the bless($this, 'configthing'); which explains why I put 33 separate bless($cfg) incantations all over the place. Dusty code that I obviously didn't understand when I wrote it.