Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to assign to an array or variable and check the existance of a string in it?

Posted on 2011-03-21
3
Medium Priority
?
275 Views
Last Modified: 2012-06-27
Hi,

#returns an array of lines
$job->body; 

Open in new window


I want to assign the output of the previous line to a variable or array and then check if there is any line in the job body that has 'gMyFile' string in it.

How can I make it in Perl?

Thanks,



0
Comment
Question by:Tolgar
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
wilcoxon earned 1000 total points
ID: 35182857
my @lines = $job->body;
my @matched = grep /gMyFile/, @lines;
print "these lines matched:\n", join("\n", @matched), "\n";
0
 

Author Comment

by:Tolgar
ID: 35183018
So how can say if matched then do something?

Thanks,
0
 
LVL 27

Assisted Solution

by:wilcoxon
wilcoxon earned 1000 total points
ID: 35183051
if (@matched) {
    # something
}
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question