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.


DWIM is Perl's answer to Gödel

In reply to Re: hash parameter question by GrandFather
in thread hash parameter question by PerlHeathen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.