perl::critic::policy::builtinfunctions::prohibitbooleangrep(3) [centos man page]
Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGUser3Contributed Perl DocumePerl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep(3)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.16.3 2014-06-09 Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep(3)
Check Out this Related Man Page
Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversaUser(Contributed Perl DocumPerl::Critic::Policy::BuiltinFunctions::ProhibitUniversalCan(3)NAME
Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalCan - Write "eval { $foo->can($name) }" instead of "UNIVERSAL::can($foo, $name)".
AFFILIATION
This Policy is part of the core Perl::Critic distribution.
DESCRIPTION
print UNIVERSAL::can($obj, 'Foo::Bar') ? 'yes' : 'no'; #not ok
print eval { $obj->can('Foo::Bar') } ? 'yes' : 'no'; #ok
As of Perl 5.9.3, the use of UNIVERSAL::can as a function has been deprecated and the method form is preferred instead. Formerly, the
functional form was recommended because it gave valid results even when the object was "undef" or an unblessed scalar. However, the
functional form makes it impossible for packages to override "can()", a technique which is crucial for implementing mock objects and some
facades.
See UNIVERSAL::can for a more thorough discussion of this topic.
CONFIGURATION
This Policy is not configurable except for the standard options.
SEE ALSO
Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalIsa
AUTHOR
Chris Dolan <cdolan@cpan.org>
COPYRIGHT
Copyright (c) 2006-2011 Chris Dolan.
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::ProhibitUniversalCan(3)
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)
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)
Hi folks...
Relatively new to scripting, but really struggling with something that will no doubt be second nature to most people on here:
Trying to get an exact match on $sub, where sub is an ip address.
subnet ()
{
clear
while true
do
... (18 Replies)
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)
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)