On Fri, 5 Dec 2003 13:57:04 +0900, Mark J. Reed wrote:
> On Fri, Dec 05, 2003 at 01:45:36PM +0900, Austin Ziegler wrote:
>> hash = { :a => 3, :b => 2, :c => 1, :d => 0}
>> hash.update({ :a => 1, :b => 2, :c => 3 })
> I know that, but in this case I have the keys and values in two arrays
> and want to match them up by position.  In other words, I want to do this:

> keys.each_with_index do
> |k, i|
> hash[k] = values[i]
> end

> The equivalent of Perl @hash{@keys} = @values.

Unfortunately, that won't work in Ruby because arrays can be keys, whereas 
in Perl, hash keys can only be scalars.

What you can do is:

hash = nil; keys.zip(value) { |k, v| (hash ||= {})[k] = v }

-austin
--
austin ziegler    * austin / halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.12.05
                                         * 08.59.33