Data Types / Scalars, hashes and arrays
Subtitles of the Movie
In this chapter we're going to look at some of the ways in which we can arrange data using Perl. First of all we're going to look at the difference between Perl's different data types, that is scalars, arrays and hashes; and then we're going to look in detail at arrays and we're also going to look at hashes. First of all, let's take a look at what these different data types are. So far we've only seen simple variables or scalars. Now a scalar variable can only contain one value. The today variable can only be one day at a time. However, with an array we can have many values at once, for instance we can have a more generic array or a hash that can contain values for today, tomorrow and the next day. So we might have Wednesday in today, and Thursday in tomorrow and so on. The difference between an array and a hash can be summed up like this. Here are three Perl variables. Now the first one is a scalar and that's the street. And the street simply contains a string, which is the name of the street. However, in order to further identify a house which is what all of these variables relate to we could identify it by looking at the street number. Now the street number is an array because there is more than one number within the street. And each of the elements in the array are sequentially ordered - 1, 2, 3, 4, 5 and so on. A hash on the other hand is more similar to the names of houses within a street. Although, there is more than one variable, they're not numerically ordered. There is no particular reason why the Laurels should come before Bag End. They're just arranged in a relatively arbitrary order within the street or the hash in which they are contained. You may also hear a hash called an associative array. So that's the basic difference between scalars, arrays and hashes. In our next movie we're going to look in more detail at what an array does.
Tutorial Information
| Course: | Perl Fundamentals |
| Author: | Joshua Mostafa |
| SKU: | 33403 |
| ISBN: | 1-9320-7215-2 |
| Release Date: | 2002-12-19 |
| Duration: | 7.5 hrs / 113 lessons |
| Work Files: |
Yes |
| Captions: | For Online University members only |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 