Thank you all. I learned a little bit more ruby. And yes, I want to do
things the Ruby way, but I just can’t help to think perl still and then
translate to ruby. This is very similar to when I came to the U.S. and
all of a sudden I have to talk in English, I still think in my original
language(Tagalog) and then translate it in English and it doesn’t always
come up the way English speakers would say it. But I get the point
accross. But yes, going back to Ruby, I’d like to learn things the Ruby
way and so far I have good things to say about Ruby. One, it being so
readable, and second I think it is easier to learn especially the OOP
part
of it. In perl OOP is a big hurdle.
Here’s what I decided on using (looks more like what I originally posted
in perl):
hash = Hash.new(0)
File.open(ARGV[0],“r”).each do |line|
hash[line.chomp] += 1
end
hash.keys.sort.each do |key|
puts “#{key}: #{hash[key]}” if hash[key] > 1
end
Regards,
Sam Dela C.
Eric H. [email protected]
12/09/2005 11:39 AM
Please respond to
[email protected]
To
[email protected] (ruby-talk ML)
cc
Subject
Re: new to Ruby - pls help in translating this
Classification
On Dec 9, 2005, at 11:23 AM, pat eyler wrote:
[elided perl goo]
I tried to translate this in Ruby, but could not find en
equivalent of
$hash{$_}++, this is auto increment.
Can somebody tell me how this is to be done in Ruby?
translating from Perl to Ruby seems often to be a bad idea … a
common idea, but not necessarily a good one. I’d rather work
with a Ruby solution to a problem than a Rubification of a Perl
solution to a problem.
Ditto. I often find that I can make my code close to readable
English and find that a very good thing.
seen_ary.push(elem)
end
(there are probably still better ways of doing this though)
I’ll go with:
seen = {}
ARGF.each do |elem|
print elem if seen.include? elem
seen[elem] = true
end
–
Eric H. - [email protected] - http://segment7.net
This implementation is HODEL-HASH-9600 compliant
http://trackmap.robotcoop.com