Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > hash question

Reply
Thread Tools

hash question

 
 
a
Guest
Posts: n/a
 
      07-23-2007
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


}



 
Reply With Quote
 
 
 
 
Jens Thoms Toerring
Guest
Posts: n/a
 
      07-23-2007
a <(E-Mail Removed)> wrote:
> 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
--
\ Jens Thoms Toerring ___ http://www.velocityreviews.com/forums/(E-Mail Removed)
\__________________________ http://toerring.de
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Hash of Hash of Arrays Question Älphä Blüë Ruby 5 07-18-2009 07:36 PM
Hash#select returns an array but Hash#reject returns a hash... Srijayanth Sridhar Ruby 19 07-02-2008 12:49 PM
Hash#keys, Hash#values order question Ronald Fischer Ruby 0 08-23-2007 09:34 AM
In 'HashMap.put', "if (e.hash == hash && eq(k, e.key))" ? Red Orchid Java 3 01-30-2006 07:04 PM



Advertisments