seaver has asked for the wisdom of the Perl Monks concerning the following question:

Dear all,

I have filled a PDB object with atoms:

$self->{'atoms'}{$number}=$atom;
I want to access all the numbers like so:
my @numbers = keys %{$self->{'atoms'}};
but in the line above, @numbers turns up empty...!?! I can reference any atom directly:
print $self->{'atoms'}{'2000'}."\n";
But just cannot get a list of the numbers, Im sure ive misunderstood something about this, but i dont know what?

cheers
Sam

Replies are listed 'Best First'.
Re: Getting keys from a referenced hash
by rkg (Hermit) on Sep 23, 2003 at 19:13 UTC
Re: Getting keys from a referenced hash
by seaver (Pilgrim) on Sep 23, 2003 at 17:20 UTC
    forget it, I found a typo:
    $self->{'$atoms'}{$number}=$atom;

    whoops, its working now.

    cheers
    Sam

      That's one good reason to use the auto-quoting mechanism of {} as a hash de-referencer. :-)

      ------
      We are the carpenters and bricklayers of the Information Age.

      The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

      Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.