You are having a problem because you are defining the function  test as a prototyped function and then invoking it in a way that disables prototype behavior.

Had the function declared and defined with the  (\%) prototype
    sub test (\%);
    ...
    sub test (\%) { ... }
been invoked as
    test(%Record1);
a hash reference would have been passed to the function. Invocation as
    &test(%Record1);
(note the  & sigil in front of  test) causes the  %Record1 hash to be 'flattened' (the prototyped behavior of taking a reference to an explicit hash is ignored) and the first parameter in the argument list happens, in the example given, to be the string 'password', which doesn't work as a hash reference. If an explicit hash reference is passed, e.g.
    &test($hashref);
everything works again, but then
    test($hashref);
(note no  & sigil) doesn't work!

The take-away lesson: Don't use prototypes unless you really understand what they do and really need that to be done.

Update: See Prototypes in perlsub (and, for good measure, Far More than Everything You've Ever Wanted to Know about Prototypes in Perl -- by Tom Christiansen).

Update: Added code example:

>perl -wMstrict -le "sub test (\%); ;; my %Record1 = ( username => '$' , password => '$' , emailAddress => '@' ); my $hashref = \%Record1; ;; print $Record1{username}; $hashref->{username} = 'NOOoooooo!'; print $Record1{username}; test(%Record1); print $Record1{username}; ;; sub test (\%) { my $reference = shift; my $test = q{Pigsy's Perfect Ten}; $reference->{username} = $test; print 'in test(): ', $reference->{username}; } " $ NOOoooooo! in test(): Pigsy's Perfect Ten Pigsy's Perfect Ten

In reply to Re^4: Elaborate Records, arrays and references by AnomalousMonk
in thread Elaborate Records, arrays and references by KyussRyn

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.