The main issue is - how perl interprets:
%$self->{simple_hash}
My attempt to explain the issue is likely to create more confusion, so I will leave that to others.

What you could use in recent perls (>=5.20) is the postfix style :

$self->%{simple_hash}

Working code:

use strict; use warnings; {package toy_module; sub new { my ($class, $args) = @_; my $self = { simple_hash => $args->{simple_hash}, simple_test_scalar => $args->{simple_test_scalar}, }; print "********** INSIDE SUBROUTINE NEW **********\n"; return bless $self, $class; } sub show_simple_hash { my $self = shift; print "********** INSIDE SUBROUTINE SHOW_SIMPLE_HASH ********* +*\n"; print "simple scalar: ".$self->{simple_test_scalar}."\n"; print "Simple Hash Key:$_\n" for keys %{$self->{simple_hash}}; } 1; } # End of package toy_module ########## MAIN ################### my $little_test_hashref = { COL_1 => 0, COL_2 => 1, COL_3 => 2, COL_4 => 3, COL_5 => 4, }; my $test_object = toy_module->new({simple_hash=>$little_test_hashref, +simple_test_scalar=>5}); $test_object->show_simple_hash;

                "From there to here, from here to there, funny things are everywhere." -- Dr. Seuss


In reply to Re: Trouble passing a hash to a module by NetWallah
in thread Trouble passing a hash to a module by mcrepeau

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.