From e3c6d986cc876295fe3a3f0760dfbe51414fbffe Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 19 Jun 2019 20:54:40 -0500 Subject: [PATCH] Bug 23084: Replace grep {^$var$} with grep {$_ eq $var} We certainly faced 3 similar bugs due to this syntax: bug 23006, bug 22941 and bug 17526. To prevent other issues related to this syntax this patch suggests to replace them all in one go. Test plan: Confirm that the 2 syntaxes are similar Eyeball the patch and confirm that there is no typo! --- C4/Acquisition.pm | 8 ++++---- C4/ImportBatch.pm | 2 +- C4/Installer/PerlModules.pm | 2 +- C4/Items.pm | 8 ++++---- C4/Members/Statistics.pm | 2 +- C4/OAI/Sets.pm | 4 ++-- C4/Overdues.pm | 2 +- C4/Search.pm | 6 +++--- C4/Serials.pm | 2 +- C4/Stats.pm | 2 +- C4/Tags.pm | 6 +++--- C4/Utils/DataTables/Members.pm | 2 +- Koha/Object.pm | 6 +++--- Koha/Objects.pm | 2 +- acqui/duplicate_orders.pl | 4 ++-- admin/preferences.pl | 2 +- admin/searchengine/elasticsearch/mappings.pl | 4 ++-- catalogue/ISBDdetail.pl | 4 ++-- catalogue/MARCdetail.pl | 4 ++-- catalogue/detail.pl | 4 ++-- catalogue/imageviewer.pl | 4 ++-- catalogue/itemsearch.pl | 2 +- catalogue/labeledMARCdetail.pl | 4 ++-- catalogue/moredetail.pl | 4 ++-- circ/circulation.pl | 2 +- clubs/templates-add-modify.pl | 4 ++-- misc/cronjobs/gather_print_notices.pl | 2 +- misc/cronjobs/longoverdue.pl | 8 ++++---- misc/migration_tools/rebuild_zebra.pl | 4 ++-- misc/translator/LangInstaller.pm | 2 +- misc/translator/translate | 2 +- opac/opac-detail.pl | 2 +- opac/opac-memberentry.pl | 2 +- opac/opac-reserve.pl | 2 +- opac/opac-search-history.pl | 2 +- opac/opac-search.pl | 2 +- opac/opac-shelves.pl | 2 +- reports/borrowers_stats.pl | 8 ++++---- tools/export.pl | 2 +- tools/letter.pl | 2 +- tools/modborrowers.pl | 4 ++-- virtualshelves/shelves.pl | 4 ++-- 42 files changed, 73 insertions(+), 73 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index c8bdf1ba83..4a84ddc6ae 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1346,7 +1346,7 @@ sub ModOrder { foreach my $orderinfokey (grep(!/ordernumber/, keys %$orderinfo)){ # ... and skip hash entries that are not in the aqorders table # FIXME : probably not the best way to do it (would be better to have a correct hash) - next unless grep(/^$orderinfokey$/, @$colnames); + next unless grep { $_ eq $orderinfokey } @$colnames; $query .= "$orderinfokey=?, "; push(@params, $orderinfo->{$orderinfokey}); } @@ -2702,7 +2702,7 @@ sub GetInvoices { if($args{order_by}) { my ($column, $direction) = split / /, $args{order_by}; - if(grep /^$column$/, @columns) { + if(grep { $_ eq $column } @columns) { $direction ||= 'ASC'; $query .= " ORDER BY $column $direction"; } @@ -2826,7 +2826,7 @@ sub AddInvoice { my @set_strs; my @set_args; foreach my $key (keys %invoice) { - if(0 < grep(/^$key$/, @columns)) { + if(0 < grep { $_ eq $key } @columns) { push @set_strs, "$key = ?"; push @set_args, ($invoice{$key} || undef); } @@ -2876,7 +2876,7 @@ sub ModInvoice { my @set_strs; my @set_args; foreach my $key (keys %invoice) { - if(0 < grep(/^$key$/, @columns)) { + if(0 < grep { $_ eq $key } @columns) { push @set_strs, "$key = ?"; push @set_args, ($invoice{$key} || undef); } diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index 7e252da83e..11889fd3ee 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -1114,7 +1114,7 @@ sub GetImportRecordsRange { my $dbh = C4::Context->dbh; my $order_by = $parameters->{order_by} || 'import_record_id'; - ( $order_by ) = grep( /^$order_by$/, qw( import_record_id title status overlay_status ) ) ? $order_by : 'import_record_id'; + ( $order_by ) = grep( { $_ eq $order_by } qw( import_record_id title status overlay_status ) ) ? $order_by : 'import_record_id'; my $order_by_direction = uc( $parameters->{order_by_direction} // 'ASC' ) eq 'DESC' ? 'DESC' : 'ASC'; diff --git a/C4/Installer/PerlModules.pm b/C4/Installer/PerlModules.pm index affcd78365..b5cdc9dfd7 100644 --- a/C4/Installer/PerlModules.pm +++ b/C4/Installer/PerlModules.pm @@ -76,7 +76,7 @@ sub version_info { no warnings ; # perl throws warns for invalid $VERSION numbers which some modules use my ( $self, $module ) = @_; - return -1 unless grep { /^$module$/ } keys(%$PERL_DEPS); + return -1 unless grep { $_ eq $module } keys(%$PERL_DEPS); $Readonly::XS::MAGIC_COOKIE="Do NOT use or require Readonly::XS unless you're me."; eval "require $module"; diff --git a/C4/Items.pm b/C4/Items.pm index f832456821..cf0e8c81d7 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -2103,11 +2103,11 @@ sub _SearchItems_build_where_fragment { push @columns, Koha::Database->new()->schema()->resultset('Biblioitem')->result_source->columns; my @operators = qw(= != > < >= <= like); my $field = $filter->{field} // q{}; - if ( (0 < grep /^$field$/, @columns) or (substr($field, 0, 5) eq 'marc:') ) { + if ( (0 < grep { $_ eq $field } @columns) or (substr($field, 0, 5) eq 'marc:') ) { my $op = $filter->{operator}; my $query = $filter->{query}; - if (!$op or (0 == grep /^$op$/, @operators)) { + if (!$op or (0 == grep { $_ eq $op } @operators)) { $op = '='; # default operator } @@ -2608,8 +2608,8 @@ sub ToggleNewStatus { |; for my $condition ( @$conditions ) { if ( - grep {/^$condition->{field}$/} @item_columns - or grep {/^$condition->{field}$/} @biblioitem_columns + grep { $_ eq $condition->{field} } @item_columns + or grep { $_ eq $condition->{field} } @biblioitem_columns ) { if ( $condition->{value} =~ /\|/ ) { my @values = split /\|/, $condition->{value}; diff --git a/C4/Members/Statistics.pm b/C4/Members/Statistics.pm index 23771c16d4..4f640bad20 100644 --- a/C4/Members/Statistics.pm +++ b/C4/Members/Statistics.pm @@ -59,7 +59,7 @@ sub get_fields { my @columns = $schema->source('Item')->columns; foreach my $fn ( @spfields ) { - push ( @ret, $fn ) if ( grep(/^$fn$/, @columns) ); + push ( @ret, $fn ) if ( grep { $_ eq $fn } @columns ); } $ret = join( '|', @ret); } diff --git a/C4/OAI/Sets.pm b/C4/OAI/Sets.pm index 44100e8794..e07e5c75c4 100644 --- a/C4/OAI/Sets.pm +++ b/C4/OAI/Sets.pm @@ -543,12 +543,12 @@ sub _evalRule { my $value = $mapping->{'marcvalue'}; my @subfield_values = $record->subfield($field, $subfield); if ($operator eq 'notequal') { - if(0 == grep /^$value$/, @subfield_values) { + if(0 == grep { $_ eq $value } @subfield_values) { return 1; } } else { - if(0 < grep /^$value$/, @subfield_values) { + if(0 < grep { $_ eq $value } @subfield_values) { return 1; } } diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 8a9f7ffb33..58b0f6d8c2 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -792,7 +792,7 @@ sub GetOverdueMessageTransportTypes { # Put 'print' in first if exists # It avoid to sent a print notice with an email or sms template is no email or sms is defined @mtts = uniq( 'print', @mtts ) - if grep {/^print$/} @mtts; + if grep { $_ eq 'print' } @mtts; return \@mtts; } diff --git a/C4/Search.pm b/C4/Search.pm index 5d68165574..232641d7ab 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -712,7 +712,7 @@ sub _get_facets_data_from_record { my $data = $field->as_string( $subfield_letters, $facet->{ sep } ); - unless ( grep { /^\Q$data\E$/ } @used_datas ) { + unless ( grep { $_ eq $data } @used_datas ) { push @used_datas, $data; $facets_counter->{ $facet->{ idx } }->{ $data }++; } @@ -1470,12 +1470,12 @@ sub buildQuery { # this happens when selecting a subject on the opac-detail page @limits = grep {!/^$/} @limits; my $original_q = $q; # without available part - unless ( grep { /^available$/ } @limits ) { + unless ( grep { $_ eq 'available' } @limits ) { $q =~ s| and \( \(allrecords,AlwaysMatches=''\) and \(not-onloan-count,st-numeric >= 1\) and \(lost,st-numeric=0\) \)||; $original_q = $q; } if ( @limits ) { - if ( grep { /^available$/ } @limits ) { + if ( grep { $_ eq 'available' } @limits ) { $q .= q| and ( (allrecords,AlwaysMatches='') and (not-onloan-count,st-numeric >= 1) and (lost,st-numeric=0) )|; delete $limits['available']; } diff --git a/C4/Serials.pm b/C4/Serials.pm index 9d34b14bae..20836995c0 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1605,7 +1605,7 @@ sub NewIssue { ### Would use substr and index But be careful to previous presence of () $recievedlist .= "; $serialseq" unless ( index( $recievedlist, $serialseq ) > 0 ); } - if ( grep { /^$status$/ } (MISSING_STATUSES) ) { + if ( grep { $_ eq $status } (MISSING_STATUSES) ) { $missinglist .= "; $serialseq" unless ( index( $missinglist, $serialseq ) > 0 ); } diff --git a/C4/Stats.pm b/C4/Stats.pm index 8a8835c346..effcc0376c 100644 --- a/C4/Stats.pm +++ b/C4/Stats.pm @@ -108,7 +108,7 @@ sub UpdateStats { } my @invalid_params = (); for my $myparam (keys %$params ) { - push @invalid_params, $myparam unless grep (/^$myparam$/, @allowed_keys); + push @invalid_params, $myparam unless grep { $_ eq $myparam } @allowed_keys; } if (scalar @invalid_params > 0 ) { croak ("UpdateStats received invalid param(s): ".join (", ",@invalid_params )); diff --git a/C4/Tags.pm b/C4/Tags.pm index 1db7accc06..a337a7ac20 100644 --- a/C4/Tags.pm +++ b/C4/Tags.pm @@ -192,7 +192,7 @@ sub get_tag_rows { carp "Empty argument key to get_tag_rows: ignoring!"; next; } - unless (1 == scalar grep {/^ $key $/x} @ok_fields) { + unless (1 == scalar grep { $_ eq $key } @ok_fields) { carp "get_tag_rows received unreconized argument key '$key'."; next; } @@ -233,7 +233,7 @@ sub get_tags { # i.e., from tags_index carp "Empty argument key to get_tags: ignoring!"; next; } - unless (1 == scalar grep {/^ $key $/x} @ok_fields) { + unless (1 == scalar grep { $_ eq $key } @ok_fields) { carp "get_tags received unreconized argument key '$key'."; next; } @@ -302,7 +302,7 @@ sub get_approval_rows { # i.e., from tags_approval carp "Empty argument key to get_approval_rows: ignoring!"; next; } - unless (1 == scalar grep {/^ $key $/x} @ok_fields) { + unless (1 == scalar grep { $_ eq $key } @ok_fields) { carp "get_approval_rows received unreconized argument key '$key'."; next; } diff --git a/C4/Utils/DataTables/Members.pm b/C4/Utils/DataTables/Members.pm index 9fb539e4f1..4504bd3047 100644 --- a/C4/Utils/DataTables/Members.pm +++ b/C4/Utils/DataTables/Members.pm @@ -38,7 +38,7 @@ sub search { # Do that after iTotalQuery! if ( defined $branchcode and $branchcode ) { @restricted_branchcodes = @restricted_branchcodes - ? grep { /^$branchcode$/ } @restricted_branchcodes + ? grep { $_ eq $branchcode } @restricted_branchcodes ? ($branchcode) : (undef) # Do not return any results : ($branchcode); diff --git a/Koha/Object.pm b/Koha/Object.pm index 694835e238..0ef986686d 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -253,7 +253,7 @@ sub set { my @columns = @{$self->_columns()}; foreach my $p ( keys %$properties ) { - unless ( grep {/^$p$/} @columns ) { + unless ( grep { $_ eq $p } @columns ) { Koha::Exceptions::Object::PropertyNotFound->throw( "No property $p for " . ref($self) ); } } @@ -661,7 +661,7 @@ sub AUTOLOAD { my @columns = @{$self->_columns()}; # Using direct setter/getter like $item->barcode() or $item->barcode($barcode); - if ( grep {/^$method$/} @columns ) { + if ( grep { $_ eq $method } @columns ) { if ( @_ ) { $self->_result()->set_column( $method, @_ ); return $self; @@ -676,7 +676,7 @@ sub AUTOLOAD { Koha::Exceptions::Object::MethodNotCoveredByTests->throw( error => sprintf("The method %s->%s is not covered by tests!", ref($self), $method), show_trace => 1 - ) unless grep { /^$method$/ } @known_methods; + ) unless grep { $_ eq $method } @known_methods; my $r = eval { $self->_result->$method(@_) }; diff --git a/Koha/Objects.pm b/Koha/Objects.pm index 6d9493308c..dd891b08f5 100644 --- a/Koha/Objects.pm +++ b/Koha/Objects.pm @@ -427,7 +427,7 @@ sub AUTOLOAD { $method =~ s/.*:://; - unless ( grep { /^$method$/ } @known_methods ) { + unless ( grep { $_ eq $method } @known_methods ) { my $class = ref($self) ? ref($self) : $self; Koha::Exceptions::Object::MethodNotCoveredByTests->throw( error => sprintf("The method %s->%s is not covered by tests!", $class, $method), diff --git a/acqui/duplicate_orders.pl b/acqui/duplicate_orders.pl index a4a02fc628..b840db13be 100755 --- a/acqui/duplicate_orders.pl +++ b/acqui/duplicate_orders.pl @@ -86,7 +86,7 @@ my @ordernumbers = split ',', scalar $input->param('ordernumbers') || ''; if ( $op eq 'select' ) { @result_order_loop = map { my $order = $_; - ( grep { /^$order->{ordernumber}$/ } @ordernumbers ) ? () : $order + ( grep {$_ eq $order->{ordernumber}} @ordernumbers ) ? () : $order } @{ C4::Acquisition::GetHistory(%$filters) }; @selected_order_loop = @@ -132,7 +132,7 @@ elsif ( $op eq 'do_duplicate' ) { for my $field ( qw(currency budget_id order_internalnote order_vendornote sort1 sort2 )) { - next if grep { /^$field$/ } @fields_to_copy; + next if grep { $_ eq $field } @fields_to_copy; $default_values->{$field} = $input->param("all_$field"); } diff --git a/admin/preferences.pl b/admin/preferences.pl index d6cc707f43..9c785bda94 100755 --- a/admin/preferences.pl +++ b/admin/preferences.pl @@ -117,7 +117,7 @@ sub _get_chunk { { text => $options{multiple}->{$option_value}, value => $option_value, - selected => (grep /^$option_value$/, @values) ? 1 : 0, + selected => (grep { $_ eq $option_value } @values) ? 1 : 0, } } keys %{ $options{multiple} } diff --git a/admin/searchengine/elasticsearch/mappings.pl b/admin/searchengine/elasticsearch/mappings.pl index 8bbbdadbc5..0ed7aa2522 100755 --- a/admin/searchengine/elasticsearch/mappings.pl +++ b/admin/searchengine/elasticsearch/mappings.pl @@ -135,7 +135,7 @@ if ( $op eq 'edit' ) { my $search_field_name = $search_field_name[$i]; my $mapping_marc_field = $mapping_marc_field[$i]; my $mapping_facet = $mapping_facet[$i]; - $mapping_facet = ( grep {/^$search_field_name$/} @facetable_field_names ) ? $mapping_facet : 0; + $mapping_facet = ( grep { $_ eq $search_field_name } @facetable_field_names ) ? $mapping_facet : 0; my $mapping_suggestible = $mapping_suggestible[$i]; my $mapping_sort = $mapping_sort[$i] eq 'undef' ? undef : $mapping_sort[$i]; my $mapping_search = $mapping_search[$i]; @@ -238,7 +238,7 @@ for my $index_name (@index_names) { suggestible => $s->get_column('suggestible'), search => $s->get_column('search'), facet => $s->get_column('facet'), - is_facetable => ( grep {/^$name$/} @facetable_field_names ) ? 1 : 0, + is_facetable => ( grep { $_ eq $name } @facetable_field_names ) ? 1 : 0, }; } diff --git a/catalogue/ISBDdetail.pl b/catalogue/ISBDdetail.pl index eb96fff1fd..9f333e1b33 100755 --- a/catalogue/ISBDdetail.pl +++ b/catalogue/ISBDdetail.pl @@ -161,13 +161,13 @@ foreach my $myorder (@allorders_using_biblio) { my $basket = $myorder->{'basketno'}; if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){ push @deletedorders_using_biblio, $myorder; - unless (grep(/^$basket$/, @baskets_deletedorders)){ + unless (grep{ $_ eq $basket } @baskets_deletedorders){ push @baskets_deletedorders,$myorder->{'basketno'}; } } else { push @orders_using_biblio, $myorder; - unless (grep(/^$basket$/, @baskets_orders)){ + unless (grep{ $_ eq $basket } @baskets_orders){ push @baskets_orders,$myorder->{'basketno'}; } } diff --git a/catalogue/MARCdetail.pl b/catalogue/MARCdetail.pl index adfe24c192..dcbf532932 100755 --- a/catalogue/MARCdetail.pl +++ b/catalogue/MARCdetail.pl @@ -337,13 +337,13 @@ foreach my $myorder (@allorders_using_biblio) { my $basket = $myorder->{'basketno'}; if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){ push @deletedorders_using_biblio, $myorder; - unless (grep(/^$basket$/, @baskets_deletedorders)){ + unless (grep{ $_ eq $basket } @baskets_deletedorders){ push @baskets_deletedorders,$myorder->{'basketno'}; } } else { push @orders_using_biblio, $myorder; - unless (grep(/^$basket$/, @baskets_orders)){ + unless (grep { $_ eq $basket } @baskets_orders){ push @baskets_orders,$myorder->{'basketno'}; } } diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 6f8853f93c..eb46ea5b95 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -555,13 +555,13 @@ foreach my $myorder (@allorders_using_biblio) { my $basket = $myorder->{'basketno'}; if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){ push @deletedorders_using_biblio, $myorder; - unless (grep(/^$basket$/, @baskets_deletedorders)){ + unless (grep{ $_ eq $basket } @baskets_deletedorders){ push @baskets_deletedorders,$myorder->{'basketno'}; } } else { push @orders_using_biblio, $myorder; - unless (grep(/^$basket$/, @baskets_orders)){ + unless (grep{ $_ eq $basket } @baskets_orders){ push @baskets_orders,$myorder->{'basketno'}; } } diff --git a/catalogue/imageviewer.pl b/catalogue/imageviewer.pl index 8b734a4ce4..67ded03c46 100755 --- a/catalogue/imageviewer.pl +++ b/catalogue/imageviewer.pl @@ -97,13 +97,13 @@ foreach my $myorder (@allorders_using_biblio) { my $basket = $myorder->{'basketno'}; if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){ push @deletedorders_using_biblio, $myorder; - unless (grep(/^$basket$/, @baskets_deletedorders)){ + unless (grep{ $_ eq $basket } @baskets_deletedorders){ push @baskets_deletedorders,$myorder->{'basketno'}; } } else { push @orders_using_biblio, $myorder; - unless (grep(/^$basket$/, @baskets_orders)){ + unless (grep{ $_ eq $basket } @baskets_orders){ push @baskets_orders,$myorder->{'basketno'}; } } diff --git a/catalogue/itemsearch.pl b/catalogue/itemsearch.pl index 4cb76d8b4e..a145149277 100755 --- a/catalogue/itemsearch.pl +++ b/catalogue/itemsearch.pl @@ -63,7 +63,7 @@ if (defined $format and $format eq 'json') { push @f, $columns[$i]; push @c, 'and'; - if ( grep /^$columns[$i]$/, qw( ccode homebranch holdingbranch location itype notforloan itemlost ) ) { + if ( grep { $_ eq $columns[$i] } qw( ccode homebranch holdingbranch location itype notforloan itemlost ) ) { push @q, "$word"; push @op, '='; } else { diff --git a/catalogue/labeledMARCdetail.pl b/catalogue/labeledMARCdetail.pl index 90543f6794..446a679fba 100755 --- a/catalogue/labeledMARCdetail.pl +++ b/catalogue/labeledMARCdetail.pl @@ -143,13 +143,13 @@ foreach my $myorder (@allorders_using_biblio) { my $basket = $myorder->{'basketno'}; if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){ push @deletedorders_using_biblio, $myorder; - unless (grep(/^$basket$/, @baskets_deletedorders)){ + unless (grep { $_ eq $basket } @baskets_deletedorders){ push @baskets_deletedorders,$myorder->{'basketno'}; } } else { push @orders_using_biblio, $myorder; - unless (grep(/^$basket$/, @baskets_orders)){ + unless (grep{ $_ eq $basket } @baskets_orders){ push @baskets_orders,$myorder->{'basketno'}; } } diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl index ccff8276a4..a736c30c8c 100755 --- a/catalogue/moredetail.pl +++ b/catalogue/moredetail.pl @@ -281,13 +281,13 @@ foreach my $myorder (@allorders_using_biblio) { my $basket = $myorder->{'basketno'}; if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){ push @deletedorders_using_biblio, $myorder; - unless (grep(/^$basket$/, @baskets_deletedorders)){ + unless (grep{ $_ eq $basket } @baskets_deletedorders){ push @baskets_deletedorders,$myorder->{'basketno'}; } } else { push @orders_using_biblio, $myorder; - unless (grep(/^$basket$/, @baskets_orders)){ + unless (grep { $_ eq $basket } @baskets_orders){ push @baskets_orders,$myorder->{'basketno'}; } } diff --git a/circ/circulation.pl b/circ/circulation.pl index 3655ec16c3..731565b268 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -126,7 +126,7 @@ if ( $batch && C4::Context->preference('BatchCheckouts') ) { $template_name = q|circ/circulation_batch_checkouts.tt|; my @batch_category_codes = split '\|', C4::Context->preference('BatchCheckoutsValidCategories'); my $categorycode = $patron->categorycode; - if ( $categorycode && grep {/^$categorycode$/} @batch_category_codes ) { + if ( $categorycode && grep { $_ eq $categorycode } @batch_category_codes ) { $batch_allowed = 1; } else { $barcodes = []; diff --git a/clubs/templates-add-modify.pl b/clubs/templates-add-modify.pl index 254a99e219..11f4606fb9 100755 --- a/clubs/templates-add-modify.pl +++ b/clubs/templates-add-modify.pl @@ -92,7 +92,7 @@ if ( $cgi->param('name') ) { # Update or create club ? Koha::Club::Template::Fields->find($field_id) : Koha::Club::Template::Field->new(); - if ( grep( /^$field_id$/, @field_delete ) ) { + if ( grep { $_ eq $field_id } @field_delete ) { $field->delete(); } else { @@ -126,7 +126,7 @@ if ( $cgi->param('name') ) { # Update or create club ? Koha::Club::Template::EnrollmentFields->find($field_id) : Koha::Club::Template::EnrollmentField->new(); - if ( grep( /^$field_id$/, @field_delete ) ) { + if ( grep { $_ eq $field_id } @field_delete ) { $field->delete(); } else { diff --git a/misc/cronjobs/gather_print_notices.pl b/misc/cronjobs/gather_print_notices.pl index 6b64a76f90..51ef7cd352 100755 --- a/misc/cronjobs/gather_print_notices.pl +++ b/misc/cronjobs/gather_print_notices.pl @@ -91,7 +91,7 @@ my @all_messages = @{ GetPrintMessages() }; @all_messages = map { my $letter_code = $_->{letter_code}; ( - grep { /^$letter_code$/ } @letter_codes + grep { $_ eq $letter_code } @letter_codes ) ? $_ : () } @all_messages if @letter_codes; exit unless @all_messages; diff --git a/misc/cronjobs/longoverdue.pl b/misc/cronjobs/longoverdue.pl index 97639374d8..c75ffd29ca 100755 --- a/misc/cronjobs/longoverdue.pl +++ b/misc/cronjobs/longoverdue.pl @@ -301,7 +301,7 @@ $borrower_category = [ map { uc $_ } @$borrower_category ]; $skip_borrower_category = [ map { uc $_} @$skip_borrower_category ]; my %category_to_process; for my $cat ( @$borrower_category ) { - unless ( grep { /^$cat$/ } @available_categories ) { + unless ( grep { $_ eq $cat } @available_categories ) { pod2usage( '-exitval' => 1, '-message' => "The category $cat does not exist in the database", @@ -311,7 +311,7 @@ for my $cat ( @$borrower_category ) { } if ( @$skip_borrower_category ) { for my $cat ( @$skip_borrower_category ) { - unless ( grep { /^$cat$/ } @available_categories ) { + unless ( grep { $_ eq $cat } @available_categories ) { pod2usage( '-exitval' => 1, '-message' => "The category $cat does not exist in the database", @@ -329,7 +329,7 @@ $itemtype = [ map { uc $_ } @$itemtype ]; $skip_itemtype = [ map { uc $_} @$skip_itemtype ]; my %itemtype_to_process; for my $it ( @$itemtype ) { - unless ( grep { /^$it$/ } @available_itemtypes ) { + unless ( grep { $_ eq $it } @available_itemtypes ) { pod2usage( '-exitval' => 1, '-message' => "The itemtype $it does not exist in the database", @@ -339,7 +339,7 @@ for my $it ( @$itemtype ) { } if ( @$skip_itemtype ) { for my $it ( @$skip_itemtype ) { - unless ( grep { /^$it$/ } @available_itemtypes ) { + unless ( grep { $_ eq $it } @available_itemtypes ) { pod2usage( '-exitval' => 1, '-message' => "The itemtype $it does not exist in the database", diff --git a/misc/migration_tools/rebuild_zebra.pl b/misc/migration_tools/rebuild_zebra.pl index 49cfc6687f..cb42164e06 100755 --- a/misc/migration_tools/rebuild_zebra.pl +++ b/misc/migration_tools/rebuild_zebra.pl @@ -146,7 +146,7 @@ if (not $biblios and not $authorities) { } our @tables_allowed_for_select = ( 'biblioitems', 'items', 'biblio', 'biblio_metadata' ); -unless ( grep { /^$table$/ } @tables_allowed_for_select ) { +unless ( grep { $_ eq $table } @tables_allowed_for_select ) { die "Cannot specify -t|--table with value '$table'. Only " . ( join ', ', @tables_allowed_for_select ) . " are allowed."; @@ -476,7 +476,7 @@ sub select_all_authorities { sub select_all_biblios { $table = 'biblioitems' - unless grep { /^$table$/ } @tables_allowed_for_select; + unless grep { $_ eq $table } @tables_allowed_for_select; my $strsth = qq{ SELECT DISTINCT biblionumber FROM $table }; $strsth.=qq{ WHERE $where } if ($where); $strsth.=qq{ LIMIT $length } if ($length && !$offset); diff --git a/misc/translator/LangInstaller.pm b/misc/translator/LangInstaller.pm index 2b1e26c502..8a7c5abcfa 100644 --- a/misc/translator/LangInstaller.pm +++ b/misc/translator/LangInstaller.pm @@ -644,7 +644,7 @@ sub extract_messages { next if $entry =~ /^\./; my $relentry = File::Spec->catfile($dir, $entry); my $abspath = File::Spec->catfile($basedir, $relentry); - if (-d $abspath and not grep /^$relentry$/, @blacklist) { + if (-d $abspath and not grep { $_ eq $relentry } @blacklist) { push @directories_to_scan, $relentry; } elsif (-f $abspath and $relentry =~ /\.(pl|pm)$/) { push @files_to_scan, $relentry; diff --git a/misc/translator/translate b/misc/translator/translate index 59a0c127ee..8683afd7db 100755 --- a/misc/translator/translate +++ b/misc/translator/translate @@ -54,7 +54,7 @@ my ($cmd, $lang) = @ARGV; $cmd = lc $cmd; if ( $cmd =~ /create|install|update/ ) { my $installer = LangInstaller->new( $lang, $pref, $verbose ); - if ( $cmd ne 'create' and $lang and not grep( /^$lang$/, @{ $installer->{langs} } ) ) { + if ( $cmd ne 'create' and $lang and not grep( {$_ eq $lang} @{ $installer->{langs} } ) ) { print "Unsupported language: $lang\n"; exit; } diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 825a35237f..19359d16c7 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -721,7 +721,7 @@ if ( not $viewallitems and @items > $max_items_to_display ) { if ( C4::Context->preference('OPACAcquisitionDetails') ) { $itm->{on_order} = 1 - if grep /^$itm->{itemnumber}$/, @itemnumbers_on_order; + if grep { $_ eq $itm->{itemnumber} } @itemnumbers_on_order; } my $itembranch = $itm->{$separatebranch}; diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl index 2272f16921..391a78f8e0 100755 --- a/opac/opac-memberentry.pl +++ b/opac/opac-memberentry.pl @@ -77,7 +77,7 @@ my $mandatory = GetMandatoryFields($action); my @libraries = Koha::Libraries->search; if ( my @libraries_to_display = split '\|', C4::Context->preference('PatronSelfRegistrationLibraryList') ) { - @libraries = map { my $b = $_; my $branchcode = $_->branchcode; grep( /^$branchcode$/, @libraries_to_display ) ? $b : () } @libraries; + @libraries = map { my $b = $_; my $branchcode = $_->branchcode; grep { $_ eq $branchcode } @libraries_to_display ? $b : () } @libraries; } my ( $min, $max ) = C4::Members::get_cardnumber_length(); if ( defined $min ) { diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index b781e32b85..d718edb30d 100755 --- a/opac/opac-reserve.pl +++ b/opac/opac-reserve.pl @@ -78,7 +78,7 @@ unless ( $can_place_hold_if_available_at_pickup ) { my @patron_categories = split '\|', C4::Context->preference('OPACHoldsIfAvailableAtPickupExceptions'); if ( @patron_categories ) { my $categorycode = $patron->categorycode; - $can_place_hold_if_available_at_pickup = grep /^$categorycode$/, @patron_categories; + $can_place_hold_if_available_at_pickup = grep { $_ eq $categorycode } @patron_categories; } } diff --git a/opac/opac-search-history.pl b/opac/opac-search-history.pl index 3ae4aadd2b..b058949984 100755 --- a/opac/opac-search-history.pl +++ b/opac/opac-search-history.pl @@ -70,7 +70,7 @@ unless ( $loggedinuser ) { @searches = map { $_->{type} ne $type ? $_ : () } @searches; } if ( @id ) { - @searches = map { my $search = $_; ( grep {/^$search->{id}$/} @id ) ? () : $_ } @searches; + @searches = map { my $search = $_; ( grep { $_ eq $search->{id} } @id ) ? () : $_ } @searches; } } C4::Search::History::set_to_session({ cgi => $cgi, search_history => \@searches }); diff --git a/opac/opac-search.pl b/opac/opac-search.pl index f8a603f4af..504c1aaef3 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -435,7 +435,7 @@ my @allowed_sortby = qw /acqdate_asc acqdate_dsc author_az author_za call_number @sort_by = $cgi->multi_param('sort_by'); $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by); foreach my $sort (@sort_by) { - if ( grep { /^$sort$/ } @allowed_sortby ) { + if ( grep { $_ eq $sort } @allowed_sortby ) { $template->param($sort => 1); } } diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index afb0f5e7e6..6c21573d5d 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -114,7 +114,7 @@ if ( $op eq 'add_form' ) { if ( $shelf ) { $op = $referer; my $sortfield = $query->param('sortfield'); - $sortfield = 'title' unless grep {/^$sortfield$/}qw( title author copyrightdate itemcallnumber dateadded ); + $sortfield = 'title' unless grep { $_ eq $sortfield } qw( title author copyrightdate itemcallnumber dateadded ); if ( $shelf->can_be_managed( $loggedinuser ) ) { $shelf->shelfname( scalar $query->param('shelfname') ); $shelf->sortfield( $sortfield ); diff --git a/reports/borrowers_stats.pl b/reports/borrowers_stats.pl index 73c655cb6e..27782c5920 100755 --- a/reports/borrowers_stats.pl +++ b/reports/borrowers_stats.pl @@ -162,17 +162,17 @@ sub calculate { my $attribute_type = $1; return unless (grep {$attribute_type eq $_->{code}} @attribute_types); } else { - return unless (grep /^$line$/, @valid_names); + return unless (grep { $_ eq $line } @valid_names); } if ($column =~ /^patron_attr\.(.*)/) { my $attribute_type = $1; return unless (grep {$attribute_type eq $_->{code}} @attribute_types); } else { - return unless (grep /^$column$/, @valid_names); + return unless (grep { $_ eq $column } @valid_names); } return if ($digits and $digits !~ /^\d+$/); - return if ($status and (grep /^$status$/, qw(debarred gonenoaddress lost)) == 0); - return if ($activity and (grep /^$activity$/, qw(active nonactive)) == 0); + return if ($status and (grep { $_ eq $status } qw(debarred gonenoaddress lost)) == 0); + return if ($activity and (grep { $_ eq $activity } qw(active nonactive)) == 0); # Filters my $linefilter; diff --git a/tools/export.pl b/tools/export.pl index 0704b57d6d..e2d75d377f 100755 --- a/tools/export.pl +++ b/tools/export.pl @@ -75,7 +75,7 @@ if ( $op eq 'export' ) { if ( $filename ) { my $mimetype = $query->uploadInfo($filename)->{'Content-Type'}; my @valid_mimetypes = qw( application/octet-stream text/csv text/plain application/vnd.ms-excel ); - unless ( grep { /^$mimetype$/ } @valid_mimetypes ) { + unless ( grep { $_ eq $mimetype } @valid_mimetypes ) { push @messages, { type => 'alert', code => 'invalid_mimetype' }; $op = ''; } diff --git a/tools/letter.pl b/tools/letter.pl index 2c5481e6cd..c658dbfbf9 100755 --- a/tools/letter.pl +++ b/tools/letter.pl @@ -266,7 +266,7 @@ sub add_form { my $preview_is_available = 0; if ($code) { - $preview_is_available = grep {/^$code$/} qw( CHECKIN CHECKOUT HOLD_SLIP ); + $preview_is_available = grep {$_ eq $code } qw( CHECKIN CHECKOUT HOLD_SLIP ); } $template->param( diff --git a/tools/modborrowers.pl b/tools/modborrowers.pl index be9852a10b..1a08a8ffbd 100755 --- a/tools/modborrowers.pl +++ b/tools/modborrowers.pl @@ -327,7 +327,7 @@ if ( $op eq 'do' ) { for my $field ( qw/surname firstname branchcode categorycode streetnumber address address2 city state zipcode country email phone mobile sort1 sort2 dateenrolled dateexpiry borrowernotes opacnote/ ) { my $value = $input->param($field); $infos->{$field} = $value if $value; - $infos->{$field} = "" if grep { /^$field$/ } @disabled; + $infos->{$field} = "" if grep { $_ eq $field } @disabled; } for my $field ( qw( dateenrolled dateexpiry debarred ) ) { @@ -384,7 +384,7 @@ if ( $op eq 'do' ) { # If this borrower is not in the category of this attribute, we don't want to modify this attribute ++$i and next if $attr_type->{category_code} and $attr_type->{category_code} ne $borrower_categorycode; my $valuename = "attr" . $i . "_value"; - if ( grep { /^$valuename$/ } @disabled ) { + if ( grep { $_ eq $valuename } @disabled ) { # The attribute is disabled, we remove it for this borrower ! eval { C4::Members::Attributes::DeleteBorrowerAttribute( $borrowernumber, $attribute ); diff --git a/virtualshelves/shelves.pl b/virtualshelves/shelves.pl index 6665c91c2a..aeb65c9496 100755 --- a/virtualshelves/shelves.pl +++ b/virtualshelves/shelves.pl @@ -102,7 +102,7 @@ if ( $op eq 'add_form' ) { if ( $shelf ) { $op = $referer; my $sortfield = $query->param('sortfield'); - $sortfield = 'title' unless grep {/^$sortfield$/}qw( title author copyrightdate itemcallnumber dateadded ); + $sortfield = 'title' unless grep { $_ eq $sortfield } qw( title author copyrightdate itemcallnumber dateadded ); if ( $shelf->can_be_managed( $loggedinuser ) ) { $shelf->shelfname( scalar $query->param('shelfname') ); $shelf->sortfield( $sortfield ); @@ -234,7 +234,7 @@ if ( $op eq 'view' ) { if ( $shelf ) { if ( $shelf->can_be_viewed( $loggedinuser ) ) { my $sortfield = $query->param('sortfield') || $shelf->sortfield || 'title'; # Passed in sorting overrides default sorting - $sortfield = 'title' unless grep $_ eq $sortfield, qw( title author copyrightdate itemcallnumber dateadded ); + $sortfield = 'title' unless grep { $_ eq $sortfield } qw( title author copyrightdate itemcallnumber dateadded ); my $direction = $query->param('direction') || 'asc'; $direction = 'asc' if $direction ne 'asc' and $direction ne 'desc'; my ( $rows, $page ); -- 2.11.0