Hi Trina.

Trina wrote:
>
> I have a hash that contains keys, but does not yet have values.
> How do you push a list of an item into the value for a particular key?
>
> I tried doing this example below, but it does not seem to be working.
> Is there anything wrong with the way this is written? Can someone give
> me suggestions for trouble shooting if this looks fine?
>
>   unless (exists $shots_OTIS{$shot}) {
>     #print "putting shot in array";
>     $shots_OTIS{$shot} = "";
>   }
>
>   push( @{$shots_OTIS{$shot}}, $endShot); ###TRIED THIS. DID NO WORK

Your problem is that you're trying too hard! If you initialise a hash
element with a string as a value then your code will try to push onto
an array referred to by that string. Since you must be using 'strict
refs' (well done!) you will get an error. If you leave the hash element
undefined instead, then Perl will automatically create an anonymous
array for you to push onto.

Try removing the 'unless' block and it should work fine.

HTH,

Rob






-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to