It's not entirely clear to me what each of the variables in your example represent, but
looks through @myarr for occurrences of $pattern which seems at odds with your description of
Quote:
If the line contains ... any element from a previously defined array
Hi,
I have the following array.
@a=( ,);
and want to
push @a,()
if the 6 is not in the $a.
This is simplified out of a longer script but im trying for days now and get sick of it.
Can any of you help me on this.
Cheers
Markus (1 Reply)
I'm using perl to do a grep of each line in a vendor file and find its occurrences in a specific directory. Any values found is saved in @dir.
.....(file opened, etc.)
....
while ($line=<FILE>){
@dir = `grep $line * `;
}
It's the specific usage of the system grep that I'm having... (7 Replies)
Hello
I want to grep a line from a file saved in some directory.
Can anyone please correct the code below:
#!/usr/bin/perl -w
$file = "/home/output.txt"
$grep_line = "closing zip for topic";
`grep $grep_line* $file`; (1 Reply)
Hello:
I butchered a shell script together, but my script kung-fu is 5 years old and all I've used for 5 years are for i loops. I hope that some perl guru can do in 5 minutes what takes me 5 weeks, so I am asking for help.
I have a simple script using "grep -A 2 'string' /path/to/file" but... (4 Replies)
Hi,
I have a huge log file (~5 GB) generated in my server. I have to search through this file for the pattern matching "ERROR" and print only those lines. There is a Perl script available in the server and I have to add a new subroutine so that it will look for this regular expression pattern in... (3 Replies)
Hi All i have this script that uses glob to look in /var/log/messages.*
my @messagefiles = glob "/var/log/messages.*";
and the code that uses it is this
grep { /NVRM: Xid/ } @messages)
but this spits out this
/var/log/messages-20111030:Oct 25 13:43:04 brent kernel: NVRM:... (10 Replies)
Hi,
Can anybody let me know how this grep will work.
The input and output is not known.
Also can you give me the details of any link where i can find clearly about grep
Thanks in advance (1 Reply)
Hi,
i want to create perl script to telnet and print the output. :
This is the script that i have so far :
#!/usr/bin/perl
use lib '/usr/lib/perl5/5.14';
use Telnet ();
$target = "192.168.5.1";
$user = "root";
$passwd = "admin123";
print... (2 Replies)
hello Everyone i am a newbie.
i have a file which contains the following
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\winclockmtq.lib
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe:... (12 Replies)
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)