From the array, every 2 values are taken and formed a key-value pair for the hash.Ħ. Just by assigning an array to a hash gets an array converted to a hash. My is actually a way of converting an array to a hash. As we said earlier, a hash is just a funny kind of array in which you look values up using key strings instead of numbers. The respective elements in the key array are mapped to elements in val array and the hash is formed. My keys are stored in a an array and the values are stored in an array The hash is populated using the hash in array context. Every 2 values are combined as a key-value pair. Retrieved: Retrieved: data222 data6 meubuntu01 So the first half of the script is Perl/Hash 101, demonstrating the simple syntax of making, retrieving from, and modifying values in a hash. Hash can also be initialized like an array. It is because the fat comma operator automatically considers the key as a string. The double quotes are optional when the fat comma is used. The operator separating the key-value pair '=>' is called Fat-comma operator.Īfter the initialization, the data in the hash will be stored as shown below where 'Jan','Feb' and 'Mar' are the keys of the hash and values against it are their respective values associated. This is the normal way of populating hash where-in every set is a key-value pair. In this article, we will see the how we can populate / initialize a hash variable in different scenarios: The big advantage of a hash is faster look-up compared to arrays. Hashes are associative arrays where the data is stored in the form of key-value pairs. Hash'es is one of the most important concepts in Perl. 10 examples of initializing a Hash variable in Perl 10 examples of initializing a Hash variable in Perl
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |