Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Look to see if array element contains string

Status
Not open for further replies.

proggybilly

Programmer
Apr 30, 2008
110
US
I have a perl program that loads the contents of a file into an array. Is there a quick way to look at the array and see if one of the elements contains "exiting now"? I could do a loop, but was hoping for something simpler. I know for the most part, what I am looking for exists in a particular element as of now, but who's to say that the next time I need it, it will be in element 6? It may be in element 10.
 
Code:
if (grep(/exiting now), @array) {
 #Do something/
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
oops


Code:
if (grep(/exiting now/), @array) { 
 #Do something
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top