Приглашаем посетить
Бестужев-Марлинский (bestuzhev-marlinskiy.lit-info.ru)

Hour 13. References and Structures

Previous Table of Contents Next

Hour 13. References and Structures

What You'll Learn in This Hour:

If Perl is your first programming language, you'll find this hour especially interesting. In most programming languages, one piece of data can be used as a reference to some other piece of data. Sometimes the piece of data used that way is called a pointer (Pascal or C); sometimes the technique is called indirect referencing (assembly language); some languages have no explicit concept of pointers at all (BASIC or Java). If you've never used references, pointers, or indirect referencing before, you may need to read parts of this chapter more than once; it can be confusing.

In Perl these pointers, called references, are used for many purposes. During this hour youwill learn 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 much like a card in an old-fashioned library card catalog. Each index card in the catalog refers to a book on the library shelves. The card indicates the kind of book it was (fiction, nonfiction, reference) and its location. Card catalogs can have several references for the same book, in different categories, and even refer to other cards in the catalog ("See Also").

In Perl, references work much the same way by pointing to individual pieces of data. The references know the kind of data they point to (scalar, array, or hash) and its location. References can be copied without changing anything about the original data, and multiple references can be made to the same piece of data. References can, in fact, refer to other references.

    Previous Table of Contents Next