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);
In reply to Re: Tied Hash to emulate double-key hash only accepts one key
by bikeNomad
in thread Tied Hash to emulate double-key hash only accepts one key
by AidanLee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |