From bcf28c9d754c71880dbf97e7d502ead58c3f8dd4 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Tue, 29 Oct 2019 18:22:14 +0000 Subject: [PATCH] TT#69200 Reimplement contains() based on List::Util's any() Change-Id: Ic3d8eb5a6bdcb6b6021706c9450f06b65db4e688 (cherry picked from commit 54704e0837c1e821b6aee90a90c27ccab7981f38) --- lib/NGCP/BulkProcessor/Array.pm | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/lib/NGCP/BulkProcessor/Array.pm b/lib/NGCP/BulkProcessor/Array.pm index f6adda6..90c1265 100644 --- a/lib/NGCP/BulkProcessor/Array.pm +++ b/lib/NGCP/BulkProcessor/Array.pm @@ -3,6 +3,8 @@ use strict; ## no critic +use List::Util qw(any); + use NGCP::BulkProcessor::Table; require Exporter; @@ -115,28 +117,19 @@ sub reversearray { } sub contains { + my ($item, $array_ptr, $case_insensitive) = @_; - my ($item,$array_ptr,$case_insensitive) = @_; - my $result = 0; - if (defined $array_ptr and ref $array_ptr eq 'ARRAY') { - if ($case_insensitive) { - foreach my $element (@$array_ptr) { - if (lc($element) eq lc($item)) { - $result = 1; - last; - } - } - } else { - foreach my $element (@$array_ptr) { - if ($element eq $item) { - $result = 1; - last; + my $result = 0; + if (defined $array_ptr and ref $array_ptr eq 'ARRAY') { + if ($case_insensitive) { + my $lc_item = lc $item; + $result = any { lc eq $lc_item } @{$array_ptr}; + } else { + $result = any { $_ eq $item } @{$array_ptr}; } - } } - } - return $result; + return int $result; } sub arrayeq {