This is now an archive web site. Some is still relevant as at February 2026 but some is purely of historic interest.
Lisa and I (Graham) are now fully retired from IT training.We have made many friends over 30 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Apache, Linux and Solaris/SunOS too. Our training notes are out of date, but with upward compatability some examples remain operational and relevant. You are welcome to make use of them "as seen", at your own risk. We now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We remain active, enjoying the times that we are retired but still healthy enough in mind and body to do things!
I am also active in many other area and still look after a lot of web sites - you can find an index ((here)) |
|
Context in Perl (written 2005-06-22)
If you write a Perl program, you refer to lists with an "@" symbol in front of the list variable name. But depending on the context of how you write it, the program may interpret it as - The list contents (if the operation is normal for a list)
- The length of the list (i.e. the element count) if that's the only thing that makes sense
- A space separated string with all the items in the list joined together (if it's in double quotes)
For example:
@salad = ("apple","banana","cherry");
$salad[3] = "tomato";
$salad[8] = "fig";
print @salad,"\n"; # list context
print @salad."\n"; # scalar context
print "@salad.\n"; # double quote context
will display:
applebananacherrytomatofig
9
apple banana cherry tomato fig.
(written 2005-06-22, updated 2006-06-05)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles P208 - Perl - Lists [28] Perl for breakfast - (2004-08-25) [140] Comparison Chart for Perl programmers - list functions - (2004-12-04) [230] Course sizes - beware of marketing statistics - (2005-02-27) [240] Conventional restraints removed - (2005-03-09) [463] Splitting the difference - (2005-10-13) [560] The fencepost problem - (2006-01-10) [622] Queues and barrel rolls in Perl - (2006-02-24) [762] Huge data files - what happened earlier? - (2006-06-15) [773] Breaking bread - (2006-06-22) [928] C++ and Perl - why did they do it THAT way? - (2006-11-16) [968] Perl - a list or a hash? - (2006-12-06) [1304] Last elements in a Perl or Python list - (2007-08-16) [1316] Filtering and altering Perl lists with grep and map - (2007-08-23) [1703] Perl ... adding to a list - end, middle, start - (2008-07-09) [1828] Perl - map to process every member of a list (array) - (2008-10-09) [1917] Out of memory during array extend - Perl - (2008-12-02) [1918] Perl Socket Programming Examples - (2008-12-02) [2067] Perl - lists do so much more than arrays - (2009-03-05) [2226] Revision / Summary of lists - Perl - (2009-06-10) [2295] The dog is not in trouble - (2009-07-17) [2484] Finding text and what surrounds it - contextual grep - (2009-10-30) [2813] Iterating over a Perl list and changing all items - (2010-06-15) [2833] Fresh Perl Teaching Examples - part 2 of 3 - (2010-06-27) [2996] Copying - duplicating data, or just adding a name? Perl and Python compared - (2010-10-12) [3400] $ is atomic and % and @ are molecular - Perl - (2011-08-20) [3548] Dark mornings, dog update, and Python and Lua courses before Christmas - (2011-12-10) [3669] Stepping through a list (or an array) in reverse order - (2012-03-23) [3870] Writing more maintainable Perl - naming fields from your data records - (2012-09-25) [3906] Taking the lead, not the dog, for a walk. - (2012-10-28) [3939] Lots of ways of doing the same thing in Perl - list iteration - (2012-12-03) [4609] Mapping an array / list without a loop - how to do it in Perl 6 - (2016-01-03)
Some other Articles
Chicken soup without the religionUse standard Perl modulesWhere do Perl modules load fromSudoku helper or sudoku cheatContext in PerlBallooning from BathWimbledon NeckImproved mining techniques!Is photoajustment an addiction?Want to be one better
|
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. So much so, and it's so long ago
that we are retired
Link to Ezine home page (for reading).
|
|