in reply to Re^2: How to pass array literal through pass by reference
in thread How to pass array literal through pass by reference
If you think of "pass by reference" in C terms, Perl subs always receive their arguments in a "pass by reference" fashion. Arguments come in the array, @_, and the elements of that array are what we call aliases to the original values. If you modify an element of that array, you are modifying the original value.
my $so_called_constant = 'unmodified'; print "constant: $so_called_constant\n"; make_modified( $so_called_constant ); print "constant: $so_called_constant\n"; make_modified( 'literal' ); sub make_modified { $_ = 'modified' for @_ } __END__ constant: unmodified constant: modified Modification of a read-only value attempted
Note that there are other places where these aliases appear naturally, and you can create them deliberately.
What we call a "reference", a C programmer would probably call a "pointer". The brackets in "[ 1, 2, 3 ]" create a reference to an array that doesn't have a name. It's exactly like the reference you get from "\@triplet" except that there isn't a variable that holds the array whence came the reference.
|
|---|