www.fachtnaroe.ie



Web This site

(Test: CSS  HTML)

Perl - Part 16

[home] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25]

Storing Multiple Values - still The Easy Way

The previous program begins to solve the issue of how to handle larger amounts of data easily and efficiently. But a question still remains:

  1. What would need to be done to change the number of names from 5 to 3?
  2. What would need to be done to change the number of names from 5 to 10?
  3. Is there anyway of shortening the asking and responding section at the end?

That being said, now that we've found such an efficient way of handling and storing larger amounts of data, there's obviously going to be a spin-off in terms of data retrieval (Q3) as well.

Copy names02.pl to names03.pl and make the alterations shown below:

In this case we are using the same technique for returning a specific name as we did for accepting them into the array; once we know its number $all_the_names[$which_name] we can retrieve just that specific name, rather than having to list all the names we have.

There's nothing wrong with being able to list all the names, but just as in a phone book there is typically only one number we want out of the thousands, it helps to be able to extract only what we want from a larger list. The array [index_variable] mechanism allows this.

Onwards...

[home] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25]

Last updated: 20120108-17:04
back to top
Fachtna Roe, Senior College, Central Technical Institute, Clonmel, Ireland.