Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Perl references - $$var and \$var notations

Perl references - $$ and $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 14:00:42)

 
Associated topics are indexed under
P217 - Perl - More than Simple Lists and Hashes!
  [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
  [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)


Back to
How do I query a database (MySQL)?
Previous and next
or
Horse's mouth home
Forward to
So what is this thing called Perl that I keep harping on about?
Some other Articles
Client side (Applet) and Server side (Servlet) Graphics in Java
What should a web site cost you?
Changing a variable behaviour in Perl - tieing
So what is this thing called Perl that I keep harping on about?
Perl references - $$var and \$var notations
How do I query a database (MySQL)?
Cornerstone Cafe, Melksham
Handling nasty characters - Perl, PHP, Python, Tcl, Lua
Taking a pride in the community
Alumni - revisiting and supporting the old University
2674 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2010: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 344596 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho