hash question

A

a

Hi

I am using object oriented Perl.
I have a class static hash variable.

sub new
{
$self->{LINKS} = %allLinks;
bless $self, $class;
return $self;
}

sub allLinks
{
-----
}

In procedure, allLinks, how can I refer to the hash $self-{LINKS}, and
append the key/value to it?

Thanks


}
 
J

Jens Thoms Toerring

a said:
I am using object oriented Perl.
I have a class static hash variable.
sub new
{
$self->{LINKS} = %allLinks;

$self seems to be a hash ref, no hash. And I don't see how you
can assign a complete hash instead of a hash ref to the hash
$self references. Did you perhaps mean

$self->{ LINKS } = \%allLinks;

or also

$self = { LINKS => \%allLinks };

Or, if you want $self->{ LINKS } to be a copy of the %allLinks
hash, then use instead e.g.

$self->{ LINKS } = { ( %allLinks ) };
bless $self, $class;
return $self;
}
sub allLinks
{
In procedure, allLinks, how can I refer to the hash $self-{LINKS}, and
append the key/value to it?

If what you assigned to $self->{ LINKS } is a hash ref then
a simple

$self->{ LINKS }->{ key } = $value;

should do (you can even shorten the left hand side a bit but I
feel it's easier to read the way I wrote it).

Regards, Jens
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,250
Latest member
Charlesreero

Latest Threads

Top