It is difficult for us to work out what you are trying to do, your description does not seem to gel with the code you show. For instance, you describe (I think) three keywords, viz. "call", "please" and "urgent" in a comma-separated string which you try to split yet your code is split'ing on whitespace, trying to work on an array rather than a scalar and you seem to be looking for a maximum of nine fields. Puzzling.
Some points to consider:-
Always use strict; and use warnings; in your code to force some coding discipline and help catch typos.
Use meaningful variable names and avoid things like @array and FILE as they convey nothing much to others trying to understand your code.
As I mention above, split works on scalars, not arrays.
index returns integers indicating position (-1 for not found) not strings so "" will never be returned.
Use ne, eq etc. when doing string comparisons, use !=, == etc. for numerical comparisons.
Consider using a regular expression rather than index to find your keywords. You can build an expression with alternation, something like if( $line =~ /(keyword1|keyword2|keyword3)/ ) { print "Found $1 in $line\n" } so you can find any of the keywords in a single test rather than having to keep looping over individual keyword searches.
I hope these points are useful and help you towards a solution. If Ihave misunderstood what you are trying to achieve please ask further and perhaps give a brief example of your data.
Cheers,
JohnGG
In reply to Re: How do I search for every occurrence of strings within an array and display them?
by johngg
in thread How do I search for every occurrence of strings within an array and display them?
by rakesh01
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |