Confusion in hash

Hi folks,

If a declare a direct hash , then the hash element works fine.

my %test = ("test",1);
print %test;
print "\n";

Here in the above, the name of the hash is predeclared...

Suppose now I need to create the hash elements dynamically in the for loop.

$test="hash";
my ${$test}=("test",1);  ## assuming $test will be replaced by hash

But receiving an error message as below..

an't declare scalar dereference in "my" at hashtest.pl line 3, near "}="
xecution of hashtest.pl aborted due to compilation errors.

I have a requirement in which I need to create the hash elements in the loop based on some variables in array and I'm using "use strict" and "use warning pragmas" .

Could anyone please let me know how to create hash variables from the elements of array?

Thanks in advance ....

#! /usr/bin/perl

my @arr = ("key1", "key2", "key3");
my %hash = ();

foreach (@arr) {
    $hash{$_} = 1;
}

foreach (keys %hash) {
    print "$_ --> $hash{$_}\n";
}