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

I have searched and found nothing to do what I want so here goes:
#!/usr/bin/perl -w use strict; my %hash; $hash{test}->{"blah 1"} = 1; $hash{test}->{"blah 2"} = 1; foreach ($hash{test}) { print "$_\n"; }
Now, this doesn't work but you should be able to get an idea of what I am trying to do, the values I want to be able to get are "blah 1" and "blah 2". I have tried:
foreach (@{$hash{test}}) { print "$_\n"; }
but that doesn't work either. can someone offer me some help?

Replies are listed 'Best First'.
Re: Accessing Hashes
by cacharbe (Curate) on Dec 17, 2001 at 06:43 UTC
    You want the keys of the hashes, then, correct?

    foreach my $key (keys %{$hash{test}}){ print $key."\n"; }

    Update: You'll want to read perlfunc:keys

    C-.

      Yes, thats exacly what I wanted, thanks.
Re: Accessing Hashes
by dug (Chaplain) on Dec 17, 2001 at 07:05 UTC
    If you made:
    foreach (@{$hash{test}}) { print "$_\n"; }
    into:
    foreach (%{$hash{test}}) { print "$_\n"; }
    you would be printing the keys and values each on a line. The "Not an ARRAY reference" error that you were receiveing was becuase of "@" as opposed to "%".