in reply to referances of hashes, and subroutines

First off, ++ for asking the question nicely and for including use strict; use warnings; in your code. Not so good however is that there is a syntax error in the code that you posted. \$A{$_} .= "hello"; #Change Values is broken syntax and should have generated an error when you tied to run the code. Mentioning the error would leave less egg on your face!

That aside, you have vaugely the right idea, you just haven't found the right way to apply it. Try this instead:

use strict; use warnings; my %hash=("bob" =>123, "tom" => "CAT"); #Assign values change (\%hash); #Print New Values print "$_ = $hash{$_}\n" foreach keys %hash; sub change{ my $hashRef = shift; #Get the reference to the values foreach (keys %$hashRef){ print "$_ = $hashRef->{$_}\n"; $hashRef->{$_} .= "hello"; #Change Values } }

Prints:

tom = CAT bob = 123 tom = CAThello bob = 123hello

Note in particular that a reference to the hash is passed to the sub and that the reference has to be dereferenced with -> to access the hash.


DWIM is Perl's answer to Gödel