Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

perl::critic::policy::builtinfunctions::prohibitbooleangrep(3pm) [debian man page]

Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGUser3Contributed Perl DocuPerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep(3pm)

NAME
Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep - Use "List::MoreUtils::any" instead of "grep" in boolean context. AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
Using "grep" in boolean context is a common idiom for checking if any elements in a list match a condition. This works because boolean context is a subset of scalar context, and grep returns the number of matches in scalar context. A non-zero number of matches means a match. But consider the case of a long array where the first element is a match. Boolean "grep" still checks all of the rest of the elements needlessly. Instead, a better solution is to use the "any" function from List::MoreUtils, which short-circuits after the first successful match to save time. CONFIGURATION
This Policy is not configurable except for the standard options. CAVEATS
The algorithm for detecting boolean context takes a LOT of shortcuts. There are lots of known false negatives. But, I was conservative in writing this, so I hope there are no false positives. AUTHOR
Chris Dolan <cdolan@cpan.org> CREDITS
Initial development of this policy was supported by a grant from the Perl Foundation. COPYRIGHT
Copyright (c) 2007-2011 Chris Dolan. Many rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. perl v5.14.2 2012-06-07 Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep(3pm)

Check Out this Related Man Page

Perl::Critic::Policy::BuiltinFunctions::RequireBlockGrepUser Contributed Perl DocumentaPerl::Critic::Policy::BuiltinFunctions::RequireBlockGrep(3)

NAME
Perl::Critic::Policy::BuiltinFunctions::RequireBlockGrep - Write "grep { $_ =~ /$pattern/ } @list" instead of "grep /$pattern/, @list". AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
The expression forms of "grep" and "map" are awkward and hard to read. Use the block forms instead. @matches = grep /pattern/, @list; #not ok @matches = grep { /pattern/ } @list; #ok @mapped = map transform($_), @list; #not ok @mapped = map { transform($_) } @list; #ok CONFIGURATION
This Policy is not configurable except for the standard options. SEE ALSO
Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap AUTHOR
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> COPYRIGHT
Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. perl v5.16.3 2014-06-09 Perl::Critic::Policy::BuiltinFunctions::RequireBlockGrep(3)
Man Page

4 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl grep

OK here's the situation: I have got these lines which I have got to parse. If the line contains a particular string and any element from a previously defined array I need to take that particular line and do some further processing. if ((grep(/$_/,$1)) && (grep($pattern,@myarr))) { #Do... (2 Replies)
Discussion started by: King Nothing
2 Replies

2. Shell Programming and Scripting

Perl extract number from file & write to file

I have 1 file that has elements as follows. Also the CVR(10) and the word "SAUCE" only appear once in the file so maybe a grep command would work? file1 CVR( 9) = 0.385E+05, ! VEHICLE CVR(10) = 0.246E+05, ! SAUCE CVR(11) = 0.162E+03, ! VEHICLE I need to extract the... (6 Replies)
Discussion started by: austinj
6 Replies

3. Shell Programming and Scripting

Need help with grep command in Perl

I am writing a Perl script that uses the grep command and instead of writing to the output file it just writes to the screen. #!/usr/bin/perl # # @ffiles = `ls CP*BUFFER*.dat`; foreach my $file (@ffiles){ @data = split(/./, $file); $filename = $data; $extension = $data; #print... (2 Replies)
Discussion started by: snillocnharas
2 Replies

4. UNIX for Beginners Questions & Answers

Check ID in a file matches to the name of the file

I have a number of text tab files in my directory named 1.vcf 2.vcf etc. Each file file has headers of 120-130 rows starting with "#", it looks like this ... ##contig=<ID=GL000194.1,length=191469,assembly=hg19> ##contig=<ID=GL000225.1,length=211173,assembly=hg19>... (7 Replies)
Discussion started by: nans
7 Replies