Or, in keeping with the DRY and KISS principles I humbly submit the lowly shell command, uniq, instead of Ruby at all: $ uniq -d <file> e.g. /tmp corey$ cat foo 1 1 2 3 3 4 /tmp corey$ uniq -d foo 1 3 /tmp corey$ Although, it was interesting to see the diversity of Ruby solutions. Corey On Dec 9, 2005, at 10:48 AM, Sam Dela Cruz 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: > > ##### Perl code > %hash = {}; > while (<>) > { > chomp; > $hash{$_}++; > } > > foreach my $key (sort keys %hash) > { > print "$key: $hash{$key}\n" if ($hash{$key} > 1); > } > > 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? Or maybe the > Ruby > way on how to attack this whole thing. Thanks. > > Regards, > Sam