Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by juo (Curate)
on May 06, 2004 at 02:44 UTC ( [id://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

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://350968]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-24 16:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found