Perl references are similar to pointers in C language,
1 Reference of scalar variables:
$ Name = "Zhang ";
$ Ref =/$ name; # "/" adds this symbol to indicate a reference to the scalar $ name, that is, $ ref points to $ name.
Print $ ref; # The printed value is the address.
Print $ ref; # print the reference value. The $ sign added for Zhang. indicates that the referenced object is a scalar rather than an array.
$ Another = $ ref; # $ another is another reference of $ name.
$ Ref = "hello"; # $ FEF is a common scalar and is no longer referenced by $ name.
2 references to Arrays:
The reference method for arrays created in Perl is similar to that for scalar variables. Use a backslash to create an array:
$ Aref = // @ arr; # $ Aref contains a reference to the entire array @ arr.
You can use this reference $ Aref to access each part of @ arr:
$ Aref [0] # access the first element of array @ arr, which is the same as $ {$ Aref} [0 ].
@ $ Aref [2, 3] # access a piece of the array, which is the same as @ {$ Aref} [2, 3 ].
@ $ Aref # access the entire array, which is the same as @ {$ Aref }.
# Example of using references to access Arrays
Foreach (@ {$ Aref })
{
Print "$ _/N ";
}