Contents | Up | Prev | Next |
Perl allows one to refer to the location of a certain variable in memory. An expression that holds such a location is called a reference. Those that are familiar with C's or Pascal's pointers may think of references as pointers. There are however, two fundamental differences:
Perl distinguishes between an array or a hash and a reference of it. The reference of any array may be taken, and a reference to an array may always be converted to its elements, but there is still a difference in functionality.
The best way to change a variable in a different scope (such as inside a different function) is to pass its reference to the function. The called function can then dereference the variable to access or modify its value.
Contents | Up | Prev | Next |
Written by Shlomi Fish