In: Computer Science
6. Store your important phone numbers in a hash. Write a program to look up umbers by the person’s name in perl language.
To write code for important phone number in Hash and look up numbers by the person's name in perl language;
Before implementing this code we have to write some explaination of this code;
Initialization of hash & fetching an element to the hash: -
A hash variable can be initialized with key/value pair during it's declaration time . There are two ways for initialize the hash variable one is using => which is called the fat arrow or fat comma .
And the second one is to put the key/value pair in double quote(" ") & separated by comma(,) .
To access the individual element from hash use the symbol ($).
These are the things we are going to used in our code:
#perl program to demonstrate the
#Fetching an element of a hash with Mobile number.
#creating hash
%rateof = (" Amol "=> 9834562730 , " john " => 9934562738, " krish " => 9735261781 );
#fetching an element of hash
print "$rateof { 'Amol'}\n" ;
print "$rateof {'john'}\n;
print "$rateof {'krish'}\n" ;
output:
9834562730
9934562738
9735261781