Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Adventure with references to lists and lists of references

I remember an old game I used to play on DEC 10 (and VAX and PDP-11) computers - the original adventure game, perhaps ([see here]) which was pure text / instruction based and you traveled North, South, East and West through the colossal cave. And there was one are - the maze - where you could get rather lost between a little maze of twisting passages, little maze of twisty passages, little twisty maze of passages, maze of little twisting passages, maze of little twisty passages, maze of twisting little passages, maze of twisty little passages, twisting little maze of passages, twisting maze of little passages, twisty little maze of passages and a twisty maze of little passages!

And I was reminded about that the other day when I was differentiating in Perl between a list of scalars, a list of references to scalars, and a reference to a list of scalars.

A series of scalars - held in a collections that's ordered (numbered from 0 upwards and sortable) is a list in Perl ... and you can create a list of scalars using round brackets:
  @numbers = (10,20,30,40);

If you want to hold pointers / references / addresses of scalars rather than the scalars themselves in a list, you'll add an extra \ character:
  @again = \(10,20,30,40);
In Perl terms, that looks like a single pointer to the list but it's not - it's an exception to the usual syntax, and it returns a whole list of pointers.

If you're really looking for a single pointer to a whole list, you'll use square brackets:
  $further = [10,20,30,40];

So ...
A list of scalars (@numbers):
  10 20 30 40
A list of references to scalars (@again):
  SCALAR(0x100800f20) SCALAR(0x100800f30) SCALAR(0x100800f40) SCALAR(0x100800f50)
and a reference to a list (of scalars, but we can't tell that from the output) ($further):
  ARRAY(0x10082c270)

There's an extended example - showing how hashes and references to hashes and context fits in too - [here].
(written 2010-12-26, updated 2011-01-03)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
P217 - Perl - More than Simple Lists and Hashes!
  [43] Hash of lists in Perl - (2004-09-09)
  [293] Course follow-ups - (2005-04-27)
  [1514] Autovivification - the magic appearance of variables in Perl - (2008-01-21)
  [2241] Perl references - $$var and \$var notations - (2009-06-15)
  [2840] Just pass a pointer - do not duplicate the data - (2010-06-30)
  [2877] Further more advanced Perl examples - (2010-07-19)
  [2996] Copying - duplicating data, or just adding a name? Perl and Python compared - (2010-10-12)
  [3007] Setting up a matrix of data (2D array) for processing in your program - (2010-10-21)
  [3072] Finding elements common to many lists / arrays - (2010-11-26)
  [3118] Arrays of arrays - or 2D arrays. How to program tables. - (2011-01-02)
  [3399] From fish, loaves and apples to money, plastic cards and BACS (Perl references explained) - (2011-08-20)
  [3406] Not multidimentional arrays - but lists of lists. Much more flexible. Perl! - (2011-08-26)
  [3444] Take the dog on a lead - do not carry her. Perl references. - (2011-09-17)
  [3577] How to do multidimensional arrays (or rather lists and hashes) in Perl - (2012-01-14)
  [3906] Taking the lead, not the dog, for a walk. - (2012-10-28)


Back to
Catering in Syracuse, the Saigon Cafe, stolen images and Christmas
Previous and next
or
Horse's mouth home
Forward to
Buckets
Some other Articles
A weighty decision
My First Christmas
Hotel and Training Course prices - the effect of the VAT rise on 4th January 2011
Buckets
Adventure with references to lists and lists of references
Catering in Syracuse, the Saigon Cafe, stolen images and Christmas
Thank you - and Happy Christmas
AND and OR operators - what is the difference between logical and bitwise varieties?
The week before Christmas
Looking ahead and behind in Regular Expressions - double matching
4759 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, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 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., 2021: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3105_Adv ... ences.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb