Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: storing data via 2 sibling keys

by btrott (Parson)
on Jun 19, 2001 at 00:56 UTC ( #89443=note: print w/ replies, xml ) Need Help??


in reply to storing data via 2 sibling keys

How about something like this:

package Tie::HashNKeys; use strict; sub TIEHASH { my $class = shift; bless {}, $class; } sub STORE { $_[0]->{ join $;, sort split /$;/, $_[1] } = $_[2]; } sub FETCH { $_[0]->{ join $;, sort split /$;/, $_[1] }; }
Sample:
tie my %hash, 'Tie::HashNKeys'; $hash{'csUsers','csGroups'} = 'foo'; print $hash{'csGroups','csUsers'}; ## prints 'foo'
Is that kind of what you want?


Comment on Re: storing data via 2 sibling keys
Select or Download Code
Replies are listed 'Best First'.
Re: Re: storing data via 2 sibling keys
by AidanLee (Chaplain) on Jun 19, 2001 at 01:09 UTC
    And once more my horizon is widened. Thanks btrott, hadn't even considered ties. This will make for a nice transparent way of doing this. Does anyone know what Data::Dumper will think of it though?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://89443]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2015-07-08 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls