On 12/9/05, Sam Dela Cruz <sam.dela.cruz / philips.com> wrote: > Hi, > > I'm starting to use Ruby in one of my projects at work. I'm coming from a > Perl background. > In my project I would need to parse a list of numbers (thousands of them) > and then return the duplicates. In perl, I can do this: > [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. > Or maybe the Ruby > way on how to attack this whole thing. Thanks. I'm assuming that your list comes from a file (but you can change that pretty easily in the code below), given that, how about something like: seen_ary = Array.new File.open("nums","r").each do |elem| print elem if seen_ary.include?(elem) seen_ary.push(elem) end (there are probably still better ways of doing this though) > > Regards, > Sam > -- thanks, -pate -------------------------