On Thu, 4 Jan 2001, Dave Thomas wrote: > jmichel / schur.institut.math.jussieu.fr (Jean Michel) writes: > > > Is there any way to get the perl behaviour? > > That's what the new block syntax does, but in a general manner. > > h = Hash.new {block} > > will execute block whenever an element with no key is accessed, > storing the result back in the hash at that key, so > > h = Hash.new {|h,k| h[k] = Array.new} > > will automatically create an array for any uninitialized hash reference, > and This is tantalizingly close to Array#to_hash functionality. Hmmmm.... arr = %w{one two three} h = Hash.new {|h,k| h[k] = arr[k-1]} h[1] # => "one" Definite possibilities, though maybe not a full-blown all-purpose interleaver/hasher/double-iterator/washing-machine/toaster/jukebox. David -- David Alan Black home: dblack / candle.superlink.net work: blackdav / shu.edu Web: http://pirate.shu.edu/~blackdav