Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: Finding hashes in hashes of hashes

by bobf (Monsignor)
on Dec 28, 2009 at 18:49 UTC ( #814649=note: print w/replies, xml ) Need Help??


in reply to Re^2: Finding hashes in hashes of hashes
in thread Finding hashes in hashes of hashes

The 'die' would go after the foreach (refer to the pseudocode that I posted). Note the comments below:

sub get_family_member { my @args = @_; my $who = shift @args; # <-- this var is not used my $families = shift @args; foreach my $family (%families) { if ($families->{$family}->{kid} eq "bart") { # <-- are you sure yo +u want to hard-code 'bart'? I think you need $who return $dfamilies->{$family}->{kid}; # <-- typo in hash name last; # <-- this will never be reached since it already returned } } # no matches found: die here }

Replies are listed 'Best First'.
Re^4: Finding hashes in hashes of hashes
by AnomalousMonk (Canon) on Dec 28, 2009 at 20:07 UTC

    bobf is quite right: the statements
        my @args = @_;
        my $who = shift @args;
        my $families = shift @args;
    are much better written as
        my ($who, $families) = @_;

    Also,  $families in the above example seems to be a hash reference,
    so use  %$families to dereference.

    Further,
        for my $family (%$families) { ... }
    won't do what you want; use
        for my $family (keys %$families) { ... }
    to iterate over the keys of the referenced hash.

Re^4: Finding hashes in hashes of hashes
by cyphy (Initiate) on Dec 29, 2009 at 14:26 UTC
    Thank you! About the typo and the who.. This is what happens, when you try to change your code to only reflect relevant parts. Next time I'll simply copy it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://814649]
help
Chatterbox?
[choroba]: beer
[choroba]: oh ok
[marto]: I crashed the ScotLUG Christmas night, having never actually been to ScotLUG
[choroba]: Corion yeah, I probably already told you about how Bjarne Stroustrup was asked whether he still watched the new tech trends and what really impressed him
[choroba]: His reply was "I watch them, but I haven't been impressed in the last 10 years. There's been nothing new". That was 2 years ago :)
[ambrus]: Ok, the docs is somewhat unclear. It does say that when an object is garbage collected, it will get cleaned up, and eventually can no longer get messages. It's not clear how long this takes, eg. I think it's kept alive until its queued events are handled
[ambrus]: in the loop, and I'm not sure if that's ok for AnyEvent. Also, it's not clear if a Timer or File object you free really is garbage collected, i.e. that Prima doesn't keep some references to it, but I hope so.
[Corion]: choroba: No, I don't remember that story, but yes, it matches my experience ;))
[ambrus]: Hopefull the object isn't kept alive, the events are processed immediately, but you'd have to read a lot of source code to be sure about that.
[Corion]: ambrus: I think both of AnyEvent and Prima are pretty tight in their memory management because they both are cooperative multitasking and (I think) both use the Perl memory management for managing things

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2016-12-09 10:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (150 votes). Check out past polls.