T
tinnews
Are there any cleaner/quicker ways of doing the following:-
@fs = ("string1", "string2", "string3", "string4");
foreach $f (@fs)
{
if (index ($line, $f)
{
# do something useful
}
}
Sorry if the syntax isn't quite right but I'm sure the idea is fairly
clear. The strings to search for (@fs) are read from a file once only
and are essentially constant, they can be in an array or a hash or
whatever is most efficient.
The line to search comes from standard input and is the 'variable'
in the problem.
So I'm receiving lines of text and I want to do something whenever
one of my 'constant' strings is found in that line.
@fs = ("string1", "string2", "string3", "string4");
foreach $f (@fs)
{
if (index ($line, $f)
{
# do something useful
}
}
Sorry if the syntax isn't quite right but I'm sure the idea is fairly
clear. The strings to search for (@fs) are read from a file once only
and are essentially constant, they can be in an array or a hash or
whatever is most efficient.
The line to search comes from standard input and is the 'variable'
in the problem.
So I'm receiving lines of text and I want to do something whenever
one of my 'constant' strings is found in that line.