Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2011-03-21
3
269 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 26

Accepted Solution

by:
wilcoxon earned 250 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 26

Assisted Solution

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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

808 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