Perhaps this will give you some ideas. Using the following test data:
Something bad happened with orchestral stuff
at com.orchestral.rhapsody.execution.route.spi.conditions.ConnectorExe
+cutor.accepts(ConnectorExecutor.java:4)
and I don't know what to do about this execution failure
but execution of orchestral stuff is important
This script:
#!/usr/bin/perl
use strict;
use warnings;
# Create test data, change logic a smidge if reading from monster log
+file
my @LogBuffer =
(
"Something bad happened with orchestral stuff",
"at com.orchestral.rhapsody.execution.route.spi.conditions.Connect
+orExecutor.accepts(ConnectorExecutor.java:4)",
"and I don't know what to do about this execution failure",
"but execution of orchestral stuff is important",
);
# Convert search strings into regular expressions
my @ParseRegExElements = ();
foreach my $ParseString (@ARGV)
{
my $RequestedRegEx = quotemeta $ParseString;
push @ParseRegExElements, $RequestedRegEx;
}
# To check for them only in the order given:
print "\n-----[ Must occur in the order given ]-----\n";
{
my $ParseRegEx = join '.*', @ParseRegExElements;
my @LogMatch = grep /$ParseRegEx/, @LogBuffer;
foreach (@LogMatch)
{
print "Match: [$_]\n";
}
}
# To check for them in any order:
print "\n-----[ May occur in any order ]-----\n";
{
my $SearchDirection = (-1); # If == -1: Searching @LogBuffer
+into @LogMatch
# If == 0: Searching @LogMatch i
+nto @NewMatch
# If == 1: Searching @NewMatch i
+nto @LogMatch
my @LogMatch = ();
my @NewMatch = ();
foreach my $ParseRegEx (@ParseRegExElements)
{
if ($SearchDirection == (-1) )
{
@LogMatch = grep /$ParseRegEx/, @LogBuffer;
}
elsif ($SearchDirection == 0)
{
@NewMatch = grep /$ParseRegEx/, @LogMatch;
}
elsif ($SearchDirection == 1)
{
@LogMatch = grep /$ParseRegEx/, @NewMatch;
}
# Toggle Direction
$SearchDirection = 1 - abs($SearchDirection);
}
if ($SearchDirection == 0)
{
foreach (@LogMatch)
{
print "Match: [$_]\n";
}
}
else
{
foreach (@NewMatch)
{
print "Match: [$_]\n";
}
}
}
print "\n-----[ Done]-----\n";
exit;
__END__
Produced these results:
D:\PerlMonks>parse1.pl orchestral execution
-----[ Must occur in the order given ]-----
Match: [at com.orchestral.rhapsody.execution.route.spi.conditions.Con
+nectorExecutor.accepts(ConnectorExecutor.java:4)]
-----[ May occur in any order ]-----
Match: [at com.orchestral.rhapsody.execution.route.spi.conditions.Con
+nectorExecutor.accepts(ConnectorExecutor.java:4)]
Match: [but execution of orchestral stuff is important]
-----[ Done]-----