Hash Structure in Perl

What is a Hash Structure?
Ways of Assigning variables to data structures?


Hash is a special kind of Data Structure, which takes very less time to find whether the specified data exists.It is used usually with large volume of data, so its internal structures also complicated.

Every element of hash has a "key" which is a string used to uniquely identify an item in the hash. The assigning "value" can be any form of scalar data. Hash variables start with the symbol "%".

Assigning Variables to data structures:

Example :

%name = ('Tom', 26, 'Peter', 51, 'Jones', 23);
%name = ('Tom' => 26, 'Peter' => 51, 'Jones' => 23);
%name = (Tom => 26, Peter => 51, Jones => 23);

In the above examples, key and value pairs are seperated by commas, but "=>" operator is equivalent to a comma, in the last example we have assigned strings without the the single quotes,even this works, the only issue is that usually perl expects a string before the "=>" operator, if used without single quotes we cannot embedd blank spaces.All the above statements are good enough to be used with perl.

Ask Questions

Ask Question