Hi,
Murphy, Ged (Bolton) <[EMAIL PROTECTED]> asked:
> I have a log containing strings as follows :
>
> 21259 audit O 72398 Mar 09 00:18 dll/ldr/elf.c
>
> The format is the same throughout with the exception of the
> 'O', as it doesn't always appear.
> I need to match when the 'O' appears and when it does, I need
> to save the file path, i.e. 'dll/ldr/elf.c'
>
> Here is a snippet from my code containing my regex
>
> if (/\sO\s.+([\w\/]+)$/) {
> print "found $1\n";
> ...
>
> However it's not working as expected, I assume due to the
> '.+' matching too much.
> Can someone help with the best method to do this?
Off the top of my head I'd say you should try
/^\d+\s+\S+\s+O.*?\s+(\S+)\s*$/
Alternatively, you could split() the string at the whitespace:
my @fields = split /\s+/, $line;
if( $fields[2] eq 'O' ){
print "found $fields[-1]\n";
}
I haven't benchmarked this, but I'd assume it would be a bit
faster than using a RE.
Of course that only works if you can be sure that there will be
not whitespace in the filename.
HTH,
Thomas
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>