O'Reilly logo

Sams Teach Yourself Perl in 21 Days, Second Edition by Rafe Colburn, Laura Lemay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining and Using Hashes

Arrays and hashes can be created and used in many of the same ways. Hashes, however, do have some peculiarities and extra features that result from the way data is stored in a hash. For example, when you put data into a hash, you'll have to keep track of two scalars for each element (the key and the value). Because hashes are unordered, you'll have to do extra work to extract values from the hash, as well as to sort them and print them. In addition, hashes perform differently than arrays in a scalar context. Read on to learn about all these things.

List Syntax and Hashes

List syntax—enclosing the elements of a list inside parentheses, separated by commas—works to create a hash just as well as it does an array. Just stick ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required