Void, Scalar, and List Context
Explore how Perl uses void, scalar, and list context to control function output and data expectations. Understand how context affects the amount of work functions perform and how it influences single and aggregate data types. This lesson helps you master context to write idiomatic and efficient Perl code.
Amount context
Amount context governs how many items we expect an operation to produce. Think of subject-verb number agreement in English. Even without knowing the formal description of this principle, you probably understand the error in the sentence, “Perl are a fun language.” (In terms of amount context, we could say that the verb “are” expects a plural noun or noun phrase.) In Perl, the number of items we request influences how many we receive.
Suppose the find_chores() sorts our household to-do list in order of priority. The number of chores we expect to read from our list influences what ...