http://www.perlmonks.org?node_id=624154

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:
%player = { 5 => 2, 4 => 3, }

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:

%shop = { 2 => 4, 5 => 22, }

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:

my @availablePosts = grep{my $item = $_;foreach my $k (keys %$_) {0 un +less $player{$k} >= $item->{$k}}1;} @posts;

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.

Spidy