Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by juo (Curate)
on May 06, 2004 at 02:44 UTC ( #350968=note: print w/ replies, xml ) Need Help??


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

my %newhash = map { $_ => $refdes_bom{$_} } grep { CPN($refdes_bom{$_}) and ITEM($refdes_bom{$_}) } keys %refdes_bom;
I have tried to make that basic routine you gave me work but failed as it will not process the keywords bar and foo. The error message I get is :
Undefined subroutine &main::CPN called at compal_test.pl line 37.
Am I missing the obvious basics here ?


Comment on Re: Re: Re: Re: Optimizing quickly hash tables by checking multiple conditions
Download Code
Re: Re: Re: Re: Re: Optimizing quickly hash tables by checking multiple conditions
by revdiablo (Prior) on May 06, 2004 at 04:50 UTC

    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://350968]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (12)
As of 2014-11-24 09:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (137 votes), past polls