On Dec 9, 2005, at 12:48 PM, 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. See if this gets you going: seen = Hash.new(0) ARGF.each_line { |line| seen[line.strip] += 1 } seen.each { |key, value| puts key if value > 1 } James Edward Gray II