Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Hash pointing to multiple items

by inq123 (Sexton)
on Mar 23, 2005 at 20:04 UTC ( #441868=note: print w/replies, xml ) Need Help??


in reply to Hash pointing to multiple items

I thought for your purpose a hash of hashes might be better? For example:

my %hash = ( artistsong1 => { 1 => 1, 3 => 1, 5 => 1 }, artistsong2 => { 2 => 1, 4 => 1 } ); # to find for ArtistSong1, does 1 exist? if($hash{artistsong1}->{1}) { print "yes, 1 does exist for artistsong1!\n"; }
If in fact, your set for song1, song2, song3 are always mutually exclusive, then it might make sense to reverse the data structure to:

my %hash = ( 1 => artistsong1, 3 => artistsong1, 5 => artistsong1, 2 => artistsong2, 4 => artistsong2, 6 => artistsong3, 7 => artistsong3 ); # to find where 1 is? my $artistsong = $hash{1};
Or of course you could also make hashes of hashes of hashes like $hash{$artist}->{$song}->{1}) && print "yes, for $artist, $song, there's 1!\n";

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2020-02-20 22:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (92 votes). Check out past polls.

    Notices?