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: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"; }
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.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";
In reply to Re^2: Elaborate Records, arrays and references
by KyussRyn
in thread Elaborate Records, arrays and references
by KyussRyn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |