S
Sam Dela Cruz
--=_alternative 006751FE882570D2_=
Content-Type: text/plain; charset="US-ASCII"
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
--=_alternative 006751FE882570D2_=--
Content-Type: text/plain; charset="US-ASCII"
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
--=_alternative 006751FE882570D2_=--