Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Help with cause of "Modification of a read-only value attempted at ..."

by shriken (Priest)
on Sep 28, 2010 at 14:25 UTC ( [id://862431]=note: print w/replies, xml ) Need Help??


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.

Replies are listed 'Best First'.
Re^3: Help with cause of "Modification of a read-only value attempted at ..."
by Corion (Patriarch) on Sep 28, 2010 at 14:32 UTC

    I don't see anything immediately wrong in relation to the error at hand. Please do as JavaFan suggests and post a small program that reproduces the error.

    You really, really should look over this code still, because it (re)declares our %DEFAULTS in two places which makes very little sense as %DEFAULTS is still visible from above.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://862431]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-04-19 16:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found