in reply to hash "member" of a module

That's because you are not returning a hash reference from your function. Within new, $self is a hash reference. When you return \$self, you return a reference to the hash reference, which is a scalar reference. See perlref or perlreftut. The following code works.

package Foo; use strict; use Data::Dumper; use Exporter; our ($VERSION,@ISA,@EXPORT,@EXPORT_OK); $VERSION = 0.99; @ISA = qw(Exporter); @EXPORT = @EXPORT_OK; @EXPORT_OK = qw(new test); sub new(){ my $self = {}; $self->{data} = {}; $self->{data}->{start_url} = "https://www.w.com/home.html"; bless $self; } sub test(){ my $self = shift; # print $self->{data}->{start_url}; # print Dumper($self); print Dumper($self->{data}); }

and

use strict; use warnings; use Foo; my $obj = Foo->new(); $obj->test();

Replies are listed 'Best First'.
Re^2: hash "member" of a module
by npc (Initiate) on Apr 15, 2009 at 18:12 UTC
    How silly of me, thank you monks.