June 2005
Beginner
480 pages
10h 31m
English
Now that you've learned the basic rules for building arrays, it's time to learn some tools to help you manipulate those arrays to perform useful tasks.
In Hour 3, “Controlling the Program's Flow,” you learned about making loops with while, for, and other constructs. Many tasks you'll want to perform involve examining each element of an array. This process is called iterating over the array. One way you could do so is to use a for loop, as follows:
@flavors=qw( chocolate vanilla strawberry mint sherbet );
for($index=0; $index<@flavors; $index++) {
print "My favorite flavor is $flavors[$index] and..."
}
print "many others.\n";
The first line initializes the array with ice cream flavors, using the ...
Read now
Unlock full access