Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by Corion (Patriarch)
on Sep 28, 2010 at 14:11 UTC ( [id://862421]=note: print w/replies, xml ) Need Help??


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

our configthing $cfg = new configthing;

You don't show us what your routine configthing::new looks like. This is where $cfg would get set. Maybe Data::Dumper can tell you more:

... use Data::Dumper; our $cfg = configthing->new(); print Dumper $cfg; emonitor::list_hosts($cfg, \@hosts);

I really, really wonder though, why you would need to (re)bless $cfg into configthing in the package emonitor.

Replies are listed 'Best First'.
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
    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.

      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://862421]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-03-19 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found