www.uic.edu/depts/accc/seminars/perliii/references.html
But they can also hide subtle bugs, so some people like to avoid them. You may have a construct like $expression where expression evaluates to a string. If you make a mistake, and it evaluates to the wrong string, perl will merrily create a new variable for you. Another problem is that syntactically, soft and hard references look nearly the same .
You cant do pointer arithmetic, but you can create and dereference them. Perl manages all the memory allocation, and it also keeps track of the kind of variable pointed to. You cant create a reference to an array and then dereference it as if it were a scalar. You cant tell the difference just by looking, but you can use the ref function if you need to. If you have a named variable, take the reference by putting a backslash in front.
A crucial point is that you must be aware of the kind of reference you are dereferencing. On the whole, you can enclose the reference in braces, and put a $, or sign in front, depending on if you are dereferencing a scalar, array, or hash.
You dont have to name an array or hash in order to create an arrayref or hashref. In the above example, although a was an array of arrayrefs, each of the arrayrefs had an explicit name. Just use list to create an anonymous arrayref, and list to create an anonymous hashref.
|