From: Jagadeesh Date: 2010-01-11T18:25:19+09:00 Subject: Re: Help On Jan 11, 11:54 am, Jeff Peng wrote: > 在 2010-01-11一的 15:30 +0900,Jagadeesh写道: > > > Thanks Jeff. yes you are correct. But have a question > > Because ruby is a strongly typed language while perl isn't. > > In perl everything doesn't need to be pre-defined with specified type. > for example, a hash: > > my %hash; > push @{$hash{key1}},"abc"; > > As you see above, though we didn't pre-define $hash{key1} as an > anonymous array, but perl does that for us silently. > > But in ruby, you can't say: > > hash = Hash.new > hash['key1'] << "abc" > > This will get an error. > Instead we would say: > > hash=Hash.new do |h,k| h['k'] = [] end > hash['key1'] << "abc" > > This will work because we have passed a block to Hash.new method, this > block will set hash's every value to a seperate empty array []. After > that the array filling ("<<" in ruby) can run. > > HTH. > > Jeff. That answered me. Thanks for your time Thanks