Better yet you could use 'tie' and create your own hash implementation like
the code below.  You will be able to set and retreive values normally except
for the fact that if you want a single value to be linked to two keys you
will need to store the value in one key and reference that key in another
key (i.e. $hash{foo} = 1; $hash{bar} = \$hash{foo}).

Rob

package MyHash;

require Tie::Hash;
@ISA = (Tie::StdHash);

sub FETCH {
        my $hash = shift;
        my $key = shift;

        if (ref $hash->{$key}) {
                return ${$hash->{$key}};
        }
        else {
                return $hash->{$key};
        }
}

sub STORE {
        my $hash = shift;
        my $key = shift;
        my $value = shift;
        
        if (ref $hash->{$key}) {
                ${$hash->{$key}} = $value;
        }
        else {
                $hash->{$key} = $value;
        }
}

package main;

tie %hash, 'MyHash';

%hash = ( one => 1, two => 2 );
$hash{oneagain} = \$hash{one};

$hash{three} = 3;
$hash{oneagain} = 'ONE';

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



-----Original Message-----
From: Balint, Jess [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 01, 2002 12:43 PM
To: '[EMAIL PROTECTED]'
Subject: Hash Question


Since this is a beginners list, I thought I would be allowed to ask this
question. Can there be multiple values for hash keys, or just one? The
reason I am asking is that I am working on a statistical program and would
need to use multiple hashes as values of another hash. If this is possible,
please let me know. Thank you.

-Jess

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to