Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Re: Re: Re: Re: Optimizing quickly hash tables by checking multiple conditions

by revdiablo (Prior)
on May 06, 2004 at 04:50 UTC ( #350988=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Re: Optimizing quickly hash tables by checking multiple conditions
in thread Optimizing quickly hash tables by checking multiple conditions

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://350988]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2018-07-16 18:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (346 votes). Check out past polls.

    Notices?