From the course: Perl 5 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Mixed data structures - Perl Tutorial
From the course: Perl 5 Essential Training
Mixed data structures
- Much of the power of references is the ability to mix different types of data into one data structure. Here's a working copy of mixed.pl from chapter 11 of the Exercise Files. And you'll notice that I have here a reference to an anonymous array with anonymous hashes in each element of the array. So, the square brackets at the beginning and end here of this structure, that indicates the anonymous array. And then, each of these lines is an anonymous hash enclosed in the curly brackets, with name, instrument, and genre for each of the keys. And then, down here for each loop, I go through the array, and for each element of the array, then I de-reference the hash for the results. And so, when I run this, you see I get, in the order, because it's an array and a for each loop, I get Jimi Hendrix, Miles Davis, Yo-Yo Ma, and Frank Zappa. Now, given this structure, I can add a row or add a record with a push, like that. And then, when I run it, you see we have one more element in our array…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.