On Wed, 12 Mar 2003 21:15:55 +0000 Nicholas Clark <[EMAIL PROTECTED]> wrote:
> On Sat, Mar 08, 2003 at 02:20:08PM +0100, Xavier Noria wrote: > > > This would be my first public module, but I am following Sam Tregar's > > recommendations from his book for this, so the distribution itself will > > be pretty standard. (Wonderful book, thank you!) > > I've not yet read the book. Does he warn that this list (like all the perl > lists) can often seem like a black hole, with messages dropping through > the cracks and never getting a reply? I only thought that I should reply > because no-one else has yet. Thank you very much your feedback! > > The module needs yet some testing, but it's time to run h2xs and work > > with a true skeleton now. Is that name OK? Would 'Hash::MultiKeyed' be > > more correct in English? Should it have to live under Tie:: instead? > > I'm not familiar with Tie::ListKeyedHash and I confess I didn't grasp > how your module works from your example code Hash::MultiKey basically allows to use a list as a key (in form of an arrayref). Different keys in the same hash can have different lengths. Different arrayrefs containing the same (eq) scalars are the same key. Perl joins lists between the brackets with $;, so one can do this kind of things already: $hash{"foo", "bar", "baz"} = 1; while (($k, $v) = each %hash) { @keys = $k eq '' ? ('') : split /$;/, $k, -1; # ... } and this is enough most of the time, but if you don't want to rely on the fact that keys do not contain $;, then Hash::MultiKey offers true multi-keys which can contain any character: $hash{["foo", "no$;problem", "baz"]} = 1; while (($k, $v) = each %hash) { @keys = @$k; # works with the entry above, length 3 # ... } Support for the original syntax with lists as in the first example will be provided as syntactic sugar nevertheless, and the risk documented. Hash::MultiKey is implemented as a tied hash with a tree behind the scenes. > I'm told (forget who by) that whether these things go into Tie or not can > cause disagreement. I'd favour not calling anything "Tie" as that's purely > an implementation detail, but I'm told that others don't agree with this, > and that a lot of existing CPAN practice puts things into the Tie namespace. I agree with you, and like the shortest Hash::MultiKey too. Indeed, last Sunday I sent a namespace registration for that name. Thanks again! -- fxn