Dear Sirs,
I have the following code, that take Hash of Hash as an iput.
Then I have function (see below) that takes a hash and a variable as input. This function will count the elements of secondary hashes and delete the hash, if it is below certain variable limit.
So with this : my %new_hoh = reduce_hash(%hoh,3);
it should return
my %hoh = ( key2 => { A => 'foo', B => 'bar', C => 'qux'}, );
But my subroutine doesn't work as it should. Is there anything wrong with it?
Yours again, Edward WIJAYA SINGAPORE
__BEGIN__ use strict; use warnings; use Data::Dumper;
my %hoh = ( key1 => { A => 'foo', B => 'bar',},
key2 => { A => 'foo', B => 'bar', C => 'qux'},
key3 => { A => 'foo',} );
my %new_hoh = reduce_hash(%hoh,3); print Dumper \%new_hoh;
#---Subroutine that do the job------- sub reduce_hash { my (%HoH,$limit) = @_; foreach my $k ( keys %HoH ) { my $count = 0; for my $k2 ( keys %{ $HoH{$k} } ) { $count++; } if ($count < $limit){ delete $HoH{$k}; } }
return %HoH; }
__END__
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>