Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
Do you know where your variables are?
 
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 ( #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.


Comment on Re^2: Help with cause of "Modification of a read-only value attempted at ..."
Select or Download Code
Re^3: Help with cause of "Modification of a read-only value attempted at ..."
by Corion (Pope) 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
Node Status?
node history
Node Type: note [id://862431]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2014-04-17 10:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (444 votes), past polls