
In Perl, if I write:
$stuff = "Porridge";
then I'm setting up a variable to contain the value "Porridge".
If I write:
$stuffat = \$stuff;
then I'm setting up a variable to contain the ADDRESS OF the variable $stuff.
So if $stuff was in memory at (hex)fe80 ... then $stuffat will be assigned that value 0xfe80. And we can look use it by using an extra $ character :
print $$stuffat;
which literally means "the contents of the contents of stuffat".
What use is this?
Lots ... not only for scalars, but for the addresses of lists too. If I write
$holder = \@biglist;
I have assigned a single scalar variable to point to what is potentially a huge dataset and (for starters) I can easily pass it around to various subs without the need to replicate the data.
Other languages have this concept - "pointer" - too. See & and * in C, and the use of & in PHP.
(written 2009-06-15, updated 2009-06-22)
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)
[3444] Take the dog on a lead - do not carry her. Perl references. - (2011-09-17)
[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)
[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)
P301 - Variables in Perl [3430] Sigils - the characters on the start of variable names in Perl, Ruby and Fortran - (2011-09-10)
[3059] Object Orientation in an hour and other Perl Lectures - (2010-11-18)
[2972] Some more advanced Perl examples from a recent course - (2010-09-27)
[2374] Lead characters on Perl variable names - (2009-08-24)
[1946] Variable Types in Perl - (2008-12-15)
[1581] What is an lvalue? (Perl, C) - (2008-03-18)
[975] Answering ALL the delegate's Perl questions - (2006-12-09)
Some other Articles
Client side (Applet) and Server side (Servlet) Graphics in JavaWhat should a web site cost you?Changing a variable behaviour in Perl - tieingSo what is this thing called Perl that I keep harping on about?Perl references - $$var and \$var notationsHow do I query a database (MySQL)?Cornerstone Cafe, MelkshamHandling nasty characters - Perl, PHP, Python, Tcl, LuaTaking a pride in the communityAlumni - revisiting and supporting the old University