in reply to reference as hash keys and values

An ordinary hash key is one single string. A "multiple key" hash key does not exist.

Of course you can combine the elements of a multiple key into one string, but that only proves that the key to a hash is a single string.

Another solution is to spread out the elements of your multiple keys over different levels of the hash.

Something like this:

my %hash = ( a => { b => [1, 2, 3], c => [4, 5, 6], }, b => { d => [7, 8, 9], e => [10, 11, 12], }, );
$hash{a}->{b} will then return the arrayref to the array 1, 2, 3, and so on.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^2: reference as hash keys and values
by Don Coyote (Hermit) on Jul 10, 2011 at 21:20 UTC

    Count Zero the issue with combining the elements in such a way is that for each key withn the multiple key set you are producing different arrays. In the op example it is that both keys within the multikey refer to array [1,2,3]. So in your example hash b and c should both hold [1,2,3].

    Could we combine the key elements like you suggest but use input processing to determine when either of the key conditions has been met for the required array.

    my %hash = ( { ab => [1, 2, 3], cd => [4, 5, 6], }, ); print $hash{'cd'} if /c|d/;
    the dereferencing syntax may be incorrect here but the example is for the processing of the key.