in reply to hash of arrays to a subrutine?
Hello tamaguchi
First of all, welcome to the monastery! We will try to help you with most of your Perl related questions (and some non-Perl related questions too). For getting a quick grip on references, I suggest tyes References Quick Reference.
I saw that you changed your title from "Hello All" to "hash of arrays to a subrutine?" - this is very good. The choice of a good title helps the readers to quickly understand your question and also helps you, the author, to take a step back and reflect on what your question actually is.
Update: I completely forgot to add a simplicistic example of how to pass a hash of arrays to a subroutine:
my %players = ( frodo => [ 'ring', 'chainmail armour' ], sam => [ 'lembas', 'chainmail armour' ], smeagol => [ 'fish', 'rabbit' ], ); # Pass the hash as a list: sub print_players { my (%players) = @_; for my $player (keys %players) { printf "$player: %s\n", join ",",@{$players{$player}}; }; }; # Pass the hash as a reference: sub print_players_ref { my ($players) = @_; for my $player (keys %$players) { printf "$player: %s\n", join ",",@{$players->{$player}}; }; }; print_players(%players); print_players_ref(\%players);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hash of arrays to a subrutine?
by tamaguchi (Pilgrim) on Jan 07, 2006 at 14:30 UTC | |
by Corion (Patriarch) on Jan 07, 2006 at 14:33 UTC |