| |||||||||||
| |||||||||||
Collection of collections (i.e. 2D array)
More than Simple Lists and Hashes! example from a Well House Consultants training course
More on More than Simple Lists and Hashes! [link]
Source code: d3 Module: P217
# Collection of collections (i.e. 2D array)
$wurked = open FH,"<","requests.xyz"; # data file may be downloaded from http://www.wellho.net/data/requests.xyz print "That was $wurked status\n"; # \n on end of die string supresses line number $wurked or die "Unable to open input fyle\n"; # %staff is a hash # Within it, the name @things is used to create lists; the name # @things is TEMPORARY - it's lost at the } of the block, but the # memory remains allocated because by that time it's a part of the # %staff hash too. while ($applicant = <FH>) { my @things = split(/\s+/,$applicant); $name = shift(@things); $staff{$name} = \@things; } # Row by row access foreach $person(keys %staff) { print "Application from \u$person ... "; @skills = @{$staff{$person}}; print "(s)he knows @skills\n"; } # Element by element access ... # All of the following do the same thing: print "Ed's second skill is ",${$staff{"ed"}}[1],"\n"; print "Ed's second skill is ",$staff{ed}->[1],"\n"; print "Ed's second skill is ",$staff{ed}[1],"\n"; __END__ Sample output: munchkin:ps11 grahamellis$ perl d3 That was 1 status Application from Ulsyees ... (s)he knows Java PHP Perl Application from Tommy ... (s)he knows Perl Java XML Application from Quentin ... (s)he knows Tcl/Tk Perl PHP Ruby Application from Jenny ... (s)he knows XML Perl Ruby ASP Application from Iris ... (s)he knows Perl MySQL Java Tcl/Tk Application from Rita ... (s)he knows PHP ASP Ruby Perl Application from Charles ... (s)he knows Perl Ruby MySQL Tcl/Tk Application from Kerry ... (s)he knows Perl Tcl/Tk Ruby MySQL Application from Queenie ... (s)he knows Ruby Perl ASP MySQL Application from Xena ... (s)he knows Java Perl PHP ASP XML Application from Ken ... (s)he knows Tcl/Tk Python Java Perl Application from John ... (s)he knows PHP XML Java Perl Application from Xavier ... (s)he knows PHP Java Perl Application from Rupert ... (s)he knows Java Python MySQL Application from Barry ... (s)he knows Python XML Java Perl PHP Application from William ... (s)he knows Ruby Perl PHP Application from Sally ... (s)he knows Tcl/Tk Perl XML MySQL Application from Zoe ... (s)he knows Ruby ASP Perl PHP Application from Ed ... (s)he knows Ruby Perl Java PHP Application from Gloria ... (s)he knows XML Perl Tcl/Tk MySQL Application from Morris ... (s)he knows Perl Java PHP Tcl/Tk Application from Florence ... (s)he knows Ruby PHP Java ASP Application from Len ... (s)he knows Perl Java MySQL Ruby Application from Cherry ... (s)he knows Perl Java Ruby MySQL Application from Barbara ... (s)he knows Tcl/Tk ASP Ruby Java Application from Tina ... (s)he knows Tcl/Tk Ruby Java Application from Ethel ... (s)he knows MySQL Perl Tcl/Tk ASP Application from Steve ... (s)he knows Tcl/Tk Perl PHP Ruby Application from Petra ... (s)he knows XML Tcl/Tk ASP Perl Ruby Application from Yollanda ... (s)he knows Ruby MySQL Tcl/Tk Application from Adam ... (s)he knows Tcl/Tk Perl Python MySQL Application from Venus ... (s)he knows Java Perl Ruby ASP Application from Zachary ... (s)he knows MySQL Java Tcl/Tk Application from Graham ... (s)he knows Java Perl Tcl/Tk Application from Ivan ... (s)he knows Ruby Java Perl Tcl/Tk MySQL Application from Leane ... (s)he knows PHP Python ASP Perl Java Application from Yuri ... (s)he knows XML PHP Perl Tcl/Tk Application from Fred ... (s)he knows MySQL Perl Java XML Application from Orpheus ... (s)he knows MySQL Ruby Tcl/Tk XML Application from Nigel ... (s)he knows PHP Python Java Perl Application from Nina ... (s)he knows Tcl/Tk Perl ASP Ruby Application from Wendy ... (s)he knows Perl Tcl/Tk ASP MySQL Application from Peter ... (s)he knows PHP Java Perl Application from Hazel ... (s)he knows PHP Python Perl Ruby ASP Application from Margaret ... (s)he knows XML Perl Ruby MySQL Tcl/Tk Application from Antonia ... (s)he knows Perl XML PHP Tcl/Tk MySQL Application from Victor ... (s)he knows Ruby Perl Tcl/Tk MySQL Application from Olivia ... (s)he knows MySQL Python ASP PHP Application from Delia ... (s)he knows XML PHP Java ASP Application from Harry ... (s)he knows PHP Python Java Application from Uva ... (s)he knows MySQL Perl Java PHP Application from David ... (s)he knows Perl Tcl/Tk Java Ed's second skill is Perl Ed's second skill is Perl Ed's second skill is Perl munchkin:ps11 grahamellis$ Learn about this subject
This module and example are covered on the following public courses:
* Perl Programming * Perl for Larger Projects * Perl bootcamp * Learning to program in Perl * Perl Programming Also available on on site courses for larger groups Books covering this topic
Yes. We have over 700 books in our library. Books
covering Perl are listed here and when you've selected a
relevant book we'll link you on to Amazon to order.
Other Examples
This example comes from our "More than Simple Lists and Hashes!" training module. You'll find a description of the topic and some
other closely related examples on the "More than Simple Lists and Hashes!" module index page.
Full description of the source code
You can learn more about this example on the training courses listed on this page,
on which you'll be given a full set of training notes.
Many other training modules are available for download (for limited use) from our download centre under an Open Training Notes License. Other resources
• Our Solutions centre provides a number of longer technical articles.
• Our Opentalk forum archive provides a question and answer centre. • The Horse's mouth provides a daily tip or thought. • Further resources are available via the resources centre. • All of these resources can be searched through through our search engine • And there's a global index here. Purpose of this website
This is a sample program, class demonstration or answer from a
training course. It's main purpose
is to provide an after-course service to customers who have attended our
public private or
on site courses, but the examples are made
generally available under conditions described below.
Web site author
Conditions of use
Past attendees on our training courses are welcome to use individual
examples in the course of their programming, but must check
the examples they use to ensure that they are suitable for their
job. Remember that some of our examples show you how not to do
things - check in your notes. Well House Consultants take no responsibility
for the suitability of these example programs to customer's needs.
This program is copyright Well House Consultants Ltd. You are forbidden from using it for running your own training courses without our prior written permission. See our page on courseware provision for more details. Any of our images within this code may NOT be reused on a public URL without our prior permission. For Bona Fide personal use, we will often grant you permission provided that you provide a link back. Commercial use on a website will incur a license fee for each image used - details on request. |
| ||||||||||
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho PAGE: http://www.wellho.net/resources/ex.php4 • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb |