develooper Front page | perl.beginners | Postings from February 2009

Re: regarding hash

Thread Previous
Jim Gibson
February 26, 2009 09:39
Re: regarding hash
Message ID:
On 2/26/09 Thu  Feb 26, 2009  6:24 AM, "Irfan Sayed"
<> scribbled:

> Hi All,
> I have sorted one array in ascending order. Now i want to store that sorted
> output (key/value pair ) in new hash. How can i do that.

By design, hashes do not have an order. Key/value pairs are stored randomly
in the hash's internal structure. This is done for efficient lookup.

There is a way to keep hash keys in a certain order (see 'perldoc -q
sorted'), but I wouldn't recommend it until you know what you are doing.

What are the key/value pairs you wish to store in a hash? You only mention a
sorted array. Are the array members to be used as keys or values in the

> Secondly, i want to delete the first occurence of key/value pair.

First in what sense? Since hashes do not have an intrinsic order, the
concept of 'first' is generally not meaningful.

Perhaps you can tell us what exactly you are trying to do. It would also
help including some sample code that you think will do what you want.

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About