ADBRITE ads links
You are here: CodeIdol.com > Perl > Intermediate Perl > Introduction To References
Intermediate Perl
| 4.1. Performing the Same Task on Many Arrays
Before the Minnow can leave on an excursion (for example, a three-hour tour), we should check every passenger and crew member to ensure they have all the required trip items in their possess...
|
|
| 4.2. Taking a Reference to an Array
Among its many other meanings, the backslash (\) character is also the "take a reference to" operator. When we use it in front of an array name, e.g., \@skipper, the result is a refere...
|
|
| 4.3. Dereferencing the Array Reference
If you look at @skipper, you'll see that it consists of two parts: the @ symbol and the name of the array. Similarly, the syntax $skipper[1] consists of the name of the array in the middle and som...
|
|
| 4.4. Getting Our Braces Off
Most of the time, the array reference we want to dereference is a simple scalar variable, such as @{$items} or ${$items}[1]. In those cases, we can drop the curly braces, unambiguously forming @$items or $$items[1].
Ho...
|
|
| 4.5. Modifying the Array
You've seen how to solve the excessive copying problem with an array reference. Now let's look at modifying
the original array.
For every missing provision, we push that provision onto an array, forcing the pa...
|
|
| 4.6. Nested Data Structures
In this example, the array @_ contains two elements, one of which is also an array. What if we take a reference to an array that also contains a reference to an array? We end up with a complex data structure...
|
|
| 4.7. Simplifying Nested Element References with Arrows
Look at the curly-brace dereferencing
again. As in our earlier example, the array reference for Gilligan's provision list is ${$all_with_names[2]}[1]. Now, what if we want to know ...
|
|
| 4.8. References to Hashes
Just as we can take a reference to an array, we can also take a reference to a hash. Once again, we use the backslash as the "take a reference to" operator:
my %gilligan_info = (
name ...
|
|
| 4.9. Exercises
You can find the answers to these exercises in "Answers for Chapter 4" in the Appendix.
4.9.1. Exercise 1 [5 min]
How many different things do these expressions refer to?
$ginger->[2][1]
${$ginger[2]}[1]
$ginger->[2]-...
|
|
You are here: CodeIdol.com > Perl > Intermediate Perl > Introduction To References
|
|
Related tags
Popular Categories
Unix books and guides
AJAX popular information
C# language guides
Windows books and cookbooks
.......
|
|