08-29-2009
Perl grep array against array
Hi,
Is there any way I can grep an array against another array?
Basically here's what I need to do.
There will be an array containing some fixed texts and I have to check whether some files contain these lines. Reading the same files over and over again for each different pattern doesnt seem to be the best of ways.
Once a match is found, I need to do some further processing on the line containing the pattern and map it against the pattern found.
Thank You.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I wish to store $string1 in $string1array a character in each array element.
Then i wish to echo the entire array to the screen so that it reads as the normal string again.
I have been trying with the code below but does not work. Please help...
To put string into array:
... (5 Replies)
Discussion started by: rorey_breaker
5 Replies
2. Shell Programming and Scripting
hi all
i have 2 array one is refernce array where as other array is generated from text file. array A has all letters from A-z and a-z and i want to find out which letters are missing in generated array and push them in another array to display them.
i have following code ....
for my $ref... (1 Reply)
Discussion started by: zedex
1 Replies
3. Shell Programming and Scripting
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)
Discussion started by: elvis00
1 Replies
4. Programming
I am facing a strange error while creating posix threads:
Given below are two snippets of code, the first one works whereas the second one gives a garbage value in the output.
Snippet 1
This works:
--------------
int *threadids;
threadids = (int *) malloc (num_threads * sizeof(int));
... (4 Replies)
Discussion started by: kmehta
4 Replies
5. Shell Programming and Scripting
Hi All,
I'm writing a nagios check that will see if our ldap servers are in sync...
I got the status data into a nested array, I would like to search key of each array and if "OK" is NOT present, echo other key=>values in the current array to a variable
so...eg...let take the single array... (1 Reply)
Discussion started by: zeekblack
1 Replies
6. Shell Programming and Scripting
Hi Everyone,
#!/usr/bin/perl
use strict;
use warnings;
my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d");
would like to split the @test array into two array:
@test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d");
means search for 3rd filed.
Thanks
find the... (0 Replies)
Discussion started by: jimmy_y
0 Replies
7. Shell Programming and Scripting
Hi everyone
I have one question about using array in perl. let say I have several log file in one folder.. example
test1.log
test2.log
test3.log
and the list goes on..
how to make an array for this file? It suppose to detect log file in the current directory and all the log file will... (3 Replies)
Discussion started by: sayachop
3 Replies
8. Shell Programming and Scripting
I have an array and two variables as below,
I need to check if $datevar is present in $filename.
If so, i need to replace $filename with the values in the array.
I need the output inside an ARRAY
How can this be done.
Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies
9. Shell Programming and Scripting
Trying to do some control flow parsing based on the index postion of an array member. Here is the pseudo code I am trying to write in (preferably in pure bash) where possible. I am thinking regex with do the trick, but need a little help.
pesudo code
if == ENDSINFIVEINTS ]]; then
do... (4 Replies)
Discussion started by: briandanielz
4 Replies
10. Shell Programming and Scripting
hello,
i need a bit of help on how to do this effectively in bash without a lot of extra looping or massive switch/case
i have a long array of M elements and a short array of N elements, so M > N always. M is not a multiple of N.
for case 1, I want to stretch N to fit M
arrayHuge
H = (... (2 Replies)
Discussion started by: f77hack
2 Replies
LEARN ABOUT DEBIAN
perl::critic::policy::controlstructures::prohibitmutatinglistfun
Perl::Critic::Policy::ControlStructures::ProhibitMutatinUsertContributePerl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions(3pm)
NAME
Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions - Don't modify "$_" in list functions.
AFFILIATION
This Policy is part of the core Perl::Critic distribution.
DESCRIPTION
"map", "grep" and other list operators are intended to transform arrays into other arrays by applying code to the array elements one by
one. For speed, the elements are referenced via a $_ alias rather than copying them. As a consequence, if the code block of the "map" or
"grep" modify $_ in any way, then it is actually modifying the source array. This IS technically allowed, but those side effects can be
quite surprising, especially when the array being passed is @_ or perhaps "values(%ENV)"! Instead authors should restrict in-place array
modification to "for(@array) { ... }" constructs instead, or use "List::MoreUtils::apply()".
CONFIGURATION
By default, this policy applies to the following list functions:
map grep
List::Util qw(first)
List::MoreUtils qw(any all none notall true false firstidx
first_index lastidx last_index insert_after
insert_after_string)
This list can be overridden the .perlcriticrc file like this:
[ControlStructures::ProhibitMutatingListFunctions]
list_funcs = map grep List::Util::first
Or, one can just append to the list like so:
[ControlStructures::ProhibitMutatingListFunctions]
add_list_funcs = Foo::Bar::listmunge
LIMITATIONS
This policy deliberately does not apply to "for (@array) { ... }" or "List::MoreUtils::apply()".
Currently, the policy only detects explicit external module usage like this:
my @out = List::MoreUtils::any {s/^foo//} @in;
and not like this:
use List::MoreUtils qw(any);
my @out = any {s/^foo//} @in;
This policy looks only for modifications of $_. Other naughtiness could include modifying $a and $b in "sort" and the like. That's beyond
the scope of this policy.
SEE ALSO
There is discussion of this policy at <http://perlmonks.org/index.pl?node_id=743445>.
AUTHOR
Chris Dolan <cdolan@cpan.org>
Michael Wolf <MichaelRWolf@att.net>
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.
perl v5.14.2 201Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions(3pm)