On Tuesday, August 12, 2003, at 02:27 PM, Trina Espinoza 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?

I'm not totally sure I understand what you're aiming for here, but I'll babble out a few ideas and see if it helps you along any. ;)


Thanks!

-T
----------------------------------------------------------
 unless (exists $shots_OTIS{$shot})  {
   #print "putting shot in array";
   $shots_OTIS{$shot} = "";

This line sets $shots_OTIS{$shot) to the empty string. That seems wrong. We wanted it to be a list, right? How about:


$shot_OTIS{$shot} = [ ];

This sets it to an anonymous array reference (a list). I'm not sure how much you do or don't know about references, but the reason I chose this is because it should make the line below work without any further changes.

However, we don't really need the line below, if we change it too this instead:

$shot_OTIS{$shot} = [ $endShot ];

That's just an anonymous array reference containing the one item of $end shot, which is what your line below does.

  }
  push( @{$shots_OTIS{$shot}}, $endShot); ###TRIED THIS. DID NO WORK

This is the part that strikes me as a little odd. You wanted a list so you could put one item in it? Perhaps this line is inside a loop you didn't show us. If so, it should work fine with my first change above.


If you really do just want one item in the value, change my above suggestions to the following and drop this push():

$shot_OTIS{$shot} = $endShot;

}

This is an extra brace, for the chunk of code you showed us.


Hope that helps a little. If not, come back and I'll babble some more...

James Gray


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



Reply via email to