in reply to Tied Hash to emulate double-key hash only accepts one key
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):$hash{'a', 'b'}
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 |