Hour 13. References and Structures

If Perl is your first programming language, this hour will be interesting for you. In most programming languages, you'll discover a concept in which one piece of data can actually be a reference to another piece of data. Sometimes they're called pointers (Pascal or C), sometimes the technique is called indirect referencing (Assembler), and some languages have no concept of pointers at all (BASIC or Java). If you've never used references, pointers, or indirect referencing before, you might need to read parts of this chapter a couple of times; it can be confusing.

Perl also has these special kinds of values, but in Perl they're called references. References are used for many purposes in Perl, but in this hour you're going to learn about how to use references to call functions with multiple arguments of complex types and how to construct complex data types such as lists of lists.

A reference is a lot like an old-fashioned library card catalog. Each index card in the catalog referred to a book in the library. The card indicated what kind of book it was (fiction, nonfiction, reference) and its location. Some card catalogs might have several references for the same book, in different categories, and even refer to other cards in the catalog ("See Also").

Perl's references are similar to the card catalog. References point to individual pieces of data. The references know what kind of data they point to (scalar, array, or hash) and where the data is. References can be copied without changing anything about the original data, and multiple references can be made to the same piece of data. References, in fact, can refer to other references.

Keeping these points in mind, settle down and take the next few pages slowly and with a clear head while we cover:

  • The basics of references

  • Common structures of references

  • A brief example to help all this make sense

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.165.247