From: David Alan Black Date: 2001-05-11T20:10:35+09:00 Subject: [ruby-talk:14990] Re: Array -> Hash convertion? On Fri, 11 May 2001, Tammo Freese wrote: > At 19:23 11.05.01 +0900, Renald Buter wrote: > >Sorry to raise another newbie question, > > > >Coming from a perl world, I like to write something like > > > > %hash = qw( foo led bar tender ) > > > >and have a hash initialized to > > > > {foo => led, bar => tender} > > > >Is anything like this possible in Ruby? > > hash = Hash[foo, led, bar, tender] That's if foo etc. are variables. In the Perl example they're strings. So you'd have to do: hash = Hash[*%w{ foo led bar tender }] or equivalent. There's been a lot of array-to-hash-to-array discussion here. A search for "to_h" at will turn up a bunch. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav