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
    What would you consider to be the advantage of using references compaired to not using them? What is the difference? Would a large program generally run faster when references are used compaired to when they are not used?

      "It depends". In general, you can regard a reference as the key to a locker. Instead of passing around the things in the locker, you pass around the key. So, references can be used to avoid copying of values, but they are more expensive on overall access. So if you have "large" values, it can be worthwhile to pass them around as references, but Data::Alias might be a better and less convoluted way of avoiding passing around the references.