|more useful options|
Using grep for many-to-many relationshipsby Spidy (Chaplain)
|on Jun 30, 2007 at 00:26 UTC||Need Help??|
Spidy has asked for the
wisdom of the Perl Monks concerning the following question:
I'm working on a browsergame where different shops will require the user to have killed different amounts of different enemies. This is accomplished using two tables inside my database: user_kills, and shop_requirements. I loop through the user's kills to build the %player hash, which looks like this:
The keys of the %player hash are enemy ID numbers, and their values are the quantity of that enemy that the player has killed.
In order to figure out which shops a player can access, I retrieve all of them and their requirements, before creating an array of hashes - each hash represents a single store, and is made up just like the %players hash:
What I need to do is loop through this array of hashes, and remove any element in the array where the player's kill counts are less than the amount required by that shop in particular.
I understand that grep is what I'd want to use for this, but I don't know how I would use it to achieve what I want to. This is what I've tried:
Where @posts is the array of hashes of shop requirements.
If someone could explain this to me, or point me in the right direction, I'd be much obliged.