Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Sub hash param by reference

by TomDLux (Vicar)
on Jul 11, 2016 at 19:58 UTC ( [id://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.