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

Re: Sub hash param by reference

by TomDLux (Vicar)
on Jul 11, 2016 at 19:58 UTC ( #1167575=note: print w/replies, xml ) Need Help??


in reply to Sub hash param by reference

So long as your subset is a nested hashref or nested array, this works nicely. I've done something similar to spread processing across dedicated routines.

my $results = process_planet( \%world ); sub process_planet { my ( $world ) = @_; my @retval; for my $country_id ( keys %$world ) { my $population = process_country( $world->{$country_id} ) +; push @retval, { $country_id => $population }; } return \@retval; } sub process_country { my ( $country ) = @_; my $national_pop; for my $city ( keys %$country ) { $national_pop += extract_city_population( $countr->{$city} + ); } return $national_pop; }

Of course, at eavh level you have to know what you're receiving, and what you're returning.

As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1167575]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2021-04-10 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?