Take the dog on a lead - do not carry her. Perl references.

Taking the dog out for a walk? It's much easier to use a lead than to carry the whole dog.
And ... in a similar vein ...
when you're passing some data into a named block of code (a.k.a. sub, subroutine, function, procedure, command, method, macro)
when programming, it's much more efficient to pass in a pointeri (a.k.a. an address or a reference)
When you pass in a pointer, you're saving yourself having to duplicate the data. That can be a serious saving if you're working with large or huge data sets. And you're also providing a powerful (but dangerous if misused) capability of altering the original data within the code that you've called.
On yesterday's
Perl course, I wrote a fresh example that compares copying a list into a Perl sub, and passing in the address. The difference is just a \ !
Copying into the sub:
addon("Ibiza",@places);
Passing a reference into the sub:
anotheradd("Magaluf",\@places);
Full source code of the demo
[here], including the source of the subs which must (of course) be coded to accept the data type that's being passed to them.
Perl's references are also an excellent way of setting up collections of collections - a very flexible and space-saving alternative to the multidimensional arrays of other languages. New example of those -
[here].
(written 2011-09-17)
Associated topics are indexed under
P217 - Perl - More than Simple Lists and Hashes! [3577] How to do multidimensional arrays (or rather lists and hashes) in Perl - (2012-01-14)
[3406] Not multidimentional arrays - but lists of lists. Much more flexible. Perl! - (2011-08-26)
[3399] From fish, loaves and apples to money, plastic cards and BACS (Perl references explained) - (2011-08-20)
[3118] Arrays of arrays - or 2D arrays. How to program tables. - (2011-01-02)
[3105] Adventure with references to lists and lists of references - (2010-12-26)
[3072] Finding elements common to many lists / arrays - (2010-11-26)
[3007] Setting up a matrix of data (2D array) for processing in your program - (2010-10-21)
[2996] Copying - duplicating data, or just adding a name? Perl and Python compared - (2010-10-12)
[2877] Further more advanced Perl examples - (2010-07-19)
[2840] Just pass a pointer - do not duplicate the data - (2010-06-30)
[2241] Perl references - $$var and \$var notations - (2009-06-15)
[1514] Autovivification - the magic appearance of variables in Perl - (2008-01-21)
[293] Course follow-ups - (2005-04-27)
[43] Hash of lists in Perl - (2004-09-09)
Some other Articles
Checking all the systems on a subnet, using Expect and TkNeedle in a haystack - finding the web server overloadAwk v PerlPerl and CGI - simple form, and monitoring script.Take the dog on a lead - do not carry her. Perl references.Getting more log information from the Apache http web serverA demonstration of how many Python facilities work togetherPressing ^C in a Python program. Also Progress Bar.Research is exciting. But should routine be automated?Python for loops - applying a temporary second name to the same object