What is in your CPN and ITEM subroutines? You have to define them to check for criteria you want. They don't just magically appear out of nowhere. Here is a fully-functional example, hopefully it will make something click for you:
my %hash = (
first => { a => 2, b => 3 },
second => { a => 3, b => 2 },
third => { a => 5, b => 4 },
fourth => { a => 4, b => 6 },
);
my %newhash = map { $_ => $hash{$_} }
grep { foo($hash{$_})
and bar($hash{$_}) }
keys %hash;
print "$_\n" foreach keys %newhash;
sub foo {
my ($href) = @_;
$href->{a} > 3;
}
sub bar {
my ($href) = @_;
$href->{b} > 2;
}
As you can see, in this example foo makes sure the value at a is greater than 3, and bar makes sure the value at b is greater than 2. The end result should print third and fourth, since those are the only keys that pass the criteria. |