hash question

Discussion in 'Perl Misc' started by a, Jul 23, 2007.

  1. a

    a Guest

    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


    }
    a, Jul 23, 2007
    #1
    1. Advertising

  2. a <> 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://toerring.de
    Jens Thoms Toerring, Jul 23, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Red Orchid
    Replies:
    3
    Views:
    1,034
  2. rp
    Replies:
    1
    Views:
    512
    red floyd
    Nov 10, 2011
  3. Ronald Fischer

    Hash#keys, Hash#values order question

    Ronald Fischer, Aug 23, 2007, in forum: Ruby
    Replies:
    0
    Views:
    151
    Ronald Fischer
    Aug 23, 2007
  4. Srijayanth Sridhar
    Replies:
    19
    Views:
    608
    David A. Black
    Jul 2, 2008
  5. Älphä Blüë

    Hash of Hash of Arrays Question

    Älphä Blüë, Jul 18, 2009, in forum: Ruby
    Replies:
    5
    Views:
    663
    Älphä Blüë
    Jul 18, 2009
Loading...

Share This Page