in reply to hash parameter question
The following code works as expected:
use warnings; use strict; use Data::Dumper; my %HoH = ( first => {1 => 'First 1', 2 => 'First 2'}, second => {1 => 'second ', 2 => 'second 2'}); print "Original hash: " . Dumper (\%HoH); my %newHoH = %{inAndOut (%HoH)}; print "\nnew hash: " . Dumper (\%newHoH); sub inAndOut { my (%hash) = @_; print "\nin sub: " . Dumper (\%hash); return {%hash}; }
Original hash: $VAR1 = { 'first' => { '1' => 'First 1', '2' => 'First 2' }, 'second' => { '1' => 'second ', '2' => 'second 2' } }; in sub: $VAR1 = { 'first' => { '1' => 'First 1', '2' => 'First 2' }, 'second' => { '1' => 'second ', '2' => 'second 2' } }; new hash: $VAR1 = { 'first' => { '1' => 'First 1', '2' => 'First 2' }, 'second' => { '1' => 'second ', '2' => 'second 2' } };
but the equivelent of your code:
use warnings; use strict; use Data::Dumper; my %HoH = ( first => {1 => 'First 1', 2 => 'First 2'}, second => {1 => 'second ', 2 => 'second 2'}); my %bogusHoH = %{bogusInAndOut (%HoH)}; print "\nbogus hash: " . Dumper (\%bogusHoH); sub bogusInAndOut { my (%hash) = @_; return %hash; }
generates warning:
Can't use string ("2/8") as a HASH ref while "strict refs" in use at C +:\Documents and Settings\Peter.WINDOMAIN\My Documents\PerlMonks\nonam +e.pl line 9.
You would do well to use strict; use warnings; in your code to catch this sort of thing earlier for yourself.
|
|---|