Ahhh, I've got to read up on that asterisk thing.
Anyways, so far here is the winner in the performance game:
def park_readfile
h = Hash.new
file = File.new("keys")
while line = file.gets
h = Hash[*line.chomp!.tr!('=', ',').split(',')]
# do stuff here...
h.clear
end
end
user system total real
park: 5.023438 0.093750 5.117188 ( 5.231126)
original: 11.398438 0.101562 11.500000 ( 11.652009)
quite a difference!
-joe
> -----Original Message-----
> From: dave / thomases.com [mailto:dave / thomases.com]
> Sent: Friday, December 15, 2000 9:37 PM
> To: ruby-talk ML
> Subject: [ruby-talk:7403] Re: Ruby performance question
>
>
> "Joseph McDonald" <joe / vpop.net> writes:
>
> > I take it back (again). it does not appear that an array
> > is automatically converted into a hash. sorry for talking
> > to myself in front of you all :-0
>
> But you can use the [] constructor
>
> Hash[1,2,3,4] # => {1=>2, 3=>4}
>
> Hash[*"a=b,c=d,e=f".tr('=', ',').split(',')]
> # => {"e"=>"f", "a"=>"b", "c"=>"d"}
>
> (note the asterisk...)
>
>
> Regards
>
>
> Dave
>