in reply to Tied Hash to emulate double-key hash only accepts one key

If you use the pseudo-two-dimensional index (using a comma):
$hash{'a', 'b'}
you only get a single key, that is, "a\034b" (unless you change $; ). This is like AWK's simulation of multi-dimensional arrays/hashes, right down to the use of SUBSEP ("\034") as a delimiter. Look at the following with Data::Dumper (I changed $; so you could see it):
use strict; use Tie::Hash; package Tie::HashNKeys; use base 'Tie::StdHash'; sub TIEHASH { my $class = shift; bless {}, $class; } sub STORE { $_[0]->{ join $;, sort split /$;/, $_[1] } = $_[2]; } sub FETCH { $_[0]->{ join $;, sort split /$;/, $_[1] }; } package main; use Data::Dumper; $; = '~'; # so it can be seen tie my %hash, 'Tie::HashNKeys'; $hash{'csUsers','csGroups'} = 'foo'; print $hash{'csGroups','csUsers'}; ## prints 'foo' print Dumper(\%hash);

Replies are listed 'Best First'.
Re: Re: Tied Hash to emulate double-key hash only accepts one key
by AidanLee (Chaplain) on Jun 21, 2001 at 23:08 UTC

    Update from the front lines: well, it seems to be working part of the time. Revelation #1:

    $hash{$foo,$bar}

    does not work the same as

    $hash{  @mykeys{'foo','bar'}  } I'll post an additional reply if i can't get the rest of it working...