in reply to Re (tilly) 1: associative array problem
in thread associative array problem
To clarify that a bit, the program can be reduced to:
Don't use strict and run it as is:my %STUDQT; $STUDQT{11} = [qw/fname mname/]; $STUDQT{11}[1][2] = 0; #$STUDQT{12} = [qw/fname mname/]; $STUDQT{12}[1][2] = 0; print qq|\$STUDQT{11}[1][2] = $STUDQT{11}[1][2]\n|, qq|\t\$STUDQT{12}[1][2] = $STUDQT{12}[1][2]\n|; $STUDQT{11}[1][2] = 'hello'; #Problem print qq|\$STUDQT{11}[1][2] = $STUDQT{11}[1][2]\n|, qq|\t\$STUDQT{12}[1][2] = $STUDQT{12}[1][2]\n|; __END__
Just as we expect. But uncomment: #$STUDQT{12} = [qw/fname mname/]; and we get:$STUDQT{11}[1][2] = 0 $STUDQT{12}[1][2] = 0 $STUDQT{11}[1][2] = hello $STUDQT{12}[1][2] = 0
$STUDQT{11}[1][2] = 0 $STUDQT{12}[1][2] = 0 $STUDQT{11}[1][2] = hello $STUDQT{12}[1][2] = hello
Turning on strict reveals that we are attempting to use 'mname' as a symbolic reference and perl guesses what we are attempting as tilly mentioned.
HTH,
Charles K. Clarkson
|
---|
In Section
Seekers of Perl Wisdom