What is hash in perl?

Showing Answers 1 - 10 of 10 Answers

SunSmiles13

  • Jul 24th, 2006
 

Hash in basically used to comment the script line.

  Was this answer useful?  Yes

Sajit

  • Aug 11th, 2006
 

Hi,

I didn't mean that. Though u r right but i want the use of HASH ( associated with associative arrays ).Could anyone try this out.

  Was this answer useful?  Yes

Sushil

  • Aug 16th, 2006
 

A hash is like an associative array, in that it is a collection of scalar data, with individual elements selected by some index value which essentialyl are scalars and called as keys. Each key corresponds to some value. Hashes are represented by % followed by some name.

  Was this answer useful?  Yes

Ram Prasad

  • Nov 2nd, 2006
 

Hash is a kind of array where in you index the values not by number but by name. For ex if you are maintaing a Driver's licence say for a particular region, you can store it in hash since licence number is unique and while accessing a particular driver you just have to give drivers licence number , rest of info like his address , age etc will be stored in the value feld for that key value.Most of Systems like Invcntory management , patient record etc use hash technique. Hope this is clear ...

  Was this answer useful?  Yes

wow_suraj

  • May 2nd, 2008
 

Hash is also known as 'Associative array' sometimes. It basicaly contains of two parts first is key and value. It is very much like a name given for a value.

Ex. A student with his/her roll number can be called as a hash. Roll number being the key and Name being the value.

Q. How to define a hash???
A. Hashes are defined with '%' symbol at the first place, following the name as per naming conventions and corresponding key and key's value.

Ex. %hshTest = ('123', RAHUL,
                           '124', SUNNY,

                           '125', ROHAN); 


Here, we have defined a hash by name %hshTest, with three keys 123, 124, 125 and values for the keys as RAHUL, SUNNY, ROHAN respectively.


We can access the value by refering the keys of the hash. Ex. if we want to get the name of student having roll number 124, we can write as


$strTest = $hshTest{'124'};

print "$strTest";

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions