Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Using map to create a hash/bag from an array

by jdporter (Paladin)
on Dec 17, 2005 at 14:19 UTC ( [id://517487]=note: print w/replies, xml ) Need Help??


in reply to Using map to create a hash/bag from an array

Semantic quibble: what you are talking about is not a bag, it is a set. A bag is just like a set, except that elements can occur more than once. You can use a hash to represent a bag, but it's a bit more involved. One simple implementation could have a key's value indicate the number of times the key occurs in the bag; but you'd still have to override the hash delete function so that it decrements the count, and only deletes the key when the count goes to zero. Another, more obvious, implementation would be to use an array. Then you'd have to write exists and delete functions. Hiding all this behind TIE would probably make some sense. All that being said, you could just use Set-Bag.

We're building the house of the future together.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-24 04:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found