I understand what ikegami and Marshall are saying but now I am seeking clarification on how it should be done in perl. In C what I would usually do is:
typedef struct s_USERINFO{ CString m_username; CString m_password; CString m_emailAddress[20]; } USERINFO; int main () { USERINFO currentUserInfo; test( currentUserInfo ); printf ("%s", currentUserInfo.m_username); } void test ( USERINFO* thisUserInfo ) { thisUserInfo->m_username = "Pigsy's Perfect Ten"; }
What I want to do is update the struct/hash in the subroutine/function and then be able to access the updated value in the main thread. In Perl my assumption on how to do this is:
use warnings; use strict; use Data::Dumper; sub test (\%); #no strict 'refs'; my $username = "PerlMonk"; my $password = "VeryGoodPassword"; my @email_addresses = ( "Monk1", "Monk2", "Monk3" ); my %Record1 = ( username => '$' , password => $password , emailAddress => [@email_addresses] ); $Record1{username} = 'NOOoooooo!'; &test( %Record1 ); sub test (\%) { my $reference = shift; my $test = "Pigsy's Perfect Ten"; $$reference->{username} = $test; print $$reference->{username}, "\n"; } print $Record1{username}, "\n";
So what I am hoping to have as an outcome of this is for the final print command to print out "Pigsy's Perfect Ten". I have two problems with this, I keep getting 'NOOoooooo!' printed out, and also I am getting the error "Can't use string ("password") as a HASH ref while "strict refs" in use at C:/xxx/test.pl line 24 ( &test( %Record1 );)." With both problems I am assuming there are problems with my syntax that I just can't figure out. Any help is appreciated.

In reply to Re^2: Elaborate Records, arrays and references by KyussRyn
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.