Perl Programming Perl Hashes |
In our previous article we covered the remaining List::Util subroutines. We used min(list) to find the minimum numeric value in a list. We also worked with its brother, the minstr(list), which as you will recall found the smallest string value in a list. We learned that uppercase letters hold a lower value, surprisingly, then lowercase ones. We also learned to use shuffle to randomly sort our lists, and sum(list) to sum up the numeric values in our lists. Hash...Not What It Sounds Like If you have worked with Access or Excel, or any grid-type program, you are familiar with the concept of a hash. These aren't exactly like a hash mind you, but a similar idea. Whereas with a typical list, you refer to the values stored in them by referencing their element or index number, like so: array[0] with hashes you look them up with their key. When you create an element in a hash, you assign it a key value. That key, plus the value, creates a record. If that is still confusing to you, never fear: after our example it should be crystal clear.
blog comments powered by Disqus |