simple hash question


I want to create a hash that stores multiple "values" for a given "key".

@value = (100);
$someHash{$someKey} = $value;

but then I want to add a second (and subsequent) value and maintain the previous values for the key. I am not sure of the syntax but something like:

push(@value, (542));
$someHash{$someKey} = $value;

so if I was to print $someHash{$someKey} I would get both 100 and 542.

I have tried serveral ways of doing it and I can't seem to get anything working :)

could you tell me how to set this up, the syntax for adding new values, and how I access a given element from the list of values for a particular key ?

thanks in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


This should help

and when printing

foreach $keys ( keys %somehash) {
 printf("%s: %s\n", $keys , join(', ', @{$hash{$keys}}));

i am sorry , there is a mistake,

should be
grimjbAuthor Commented:
I tried that but I got compliation errors on the push line. Here is what I wrote to test this method:



$value = 876;
$index = "elephant"

push(@{$theHash{$index}}, $value);

foreach $k (keys %theHash)
     print $theHash{$k};

any ideas ?
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

just cut and paste this code, and try
it is working absolutely fine in my system
if it dosent work do tell


$value1 = "something";
$value2 = "againsomething";

$index = "keyofhash";

push (@{$hash{$index}}, $value1);
push (@{$hash{$index}}, $value2);

foreach $keys (keys (%hash) ) {
  printf("%s:  %s\n", $keys, join(', ', @{$hash{$keys}}));
exit 0;


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The problem with ur code was that a semi colon was missing at the end of $index = "elephant"
That was the error
You also have to mention the path of perl
just do  

which perl

and you will know the directory where perl exists in your system
grimjbAuthor Commented:
That hit the spot :) I can't believe I missed a semi.

thanks for the help!!
grimjbAuthor Commented:
prady_21 was really good to put up with a perl newbie like me :) thanks again
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.