From ef0c810d9441c8f7a4ca84d4c07e69e8c930b51c Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Thu, 7 Nov 2019 19:13:20 +0100 Subject: [PATCH] TT#69200 Refactor getting the size of a hash Change-Id: I1b2e401d009a9712e059a68e6d62b193acb98596 (cherry picked from commit d167d55a90a228c59086225aef3273dc1637edde) --- lib/NGCP/BulkProcessor/Array.pm | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/NGCP/BulkProcessor/Array.pm b/lib/NGCP/BulkProcessor/Array.pm index c7bfd64..867047b 100644 --- a/lib/NGCP/BulkProcessor/Array.pm +++ b/lib/NGCP/BulkProcessor/Array.pm @@ -304,20 +304,22 @@ sub array_to_map { } +sub _hash_size { + my $hash_ref = shift; + + if (defined $hash_ref and ref $hash_ref eq 'HASH') { + return scalar keys %{$hash_ref}; + } else { + return 0; + } +} + + sub mapeq { my ($map_prt1,$map_prt2,$case_insensitive) = @_; - my $key_count1; - my $key_count2; - if (defined $map_prt1 and ref $map_prt1 eq 'HASH') { - $key_count1 = (scalar keys %$map_prt1); - } else { - $key_count1 = 0; - } - if (defined $map_prt2 and ref $map_prt2 eq 'HASH') { - $key_count2 = (scalar keys %$map_prt2); - } else { - $key_count2 = 0; - } + my $key_count1 = _hash_size($map_prt1); + my $key_count2 = _hash_size($map_prt2); + if ($key_count1 != $key_count2) { return 0; #print "they don't have the same number of keys\n"; } else {