|
The
suggested code does find every instance of the pid at the beginning of a line
after the first instance (barring any typos). With the advantage of a
sample source file, I'd tidy the code up this way:
$pid =
'';
while (<DRWTSN>)
{
if
(($pid) =
/^\s*App:.+pid=(\d+)/)
{
print "<b>$_</b><br>"; next;
} if
($pid ne '' and /^\s*$pid\s/)
{
print "$_<br>";
next;
}
if (/^\s*When:/)
{
print "$_<br>"; next;
} if (/^\s*Exception\s+number:/) { print "$_<br><br><br>"; } } The $pid
variable is initialized to a null string. When the first if statement
matches, the regex captures the pid string (e.g., ($pid) = /.+pid=(\d+)/)
and stores it in the $pid variable.
When the
$pid variable is non-null, the second if statement uses a regex that includes
the $pid variable.
Colons
aren't special in regexes and don't need to be quoted. \S means the
opposite of \s. I've also added some beginning of line anchors to minimize
unnecessary searching.
This
routine is not going to print the results in exactly the order you
specified. In order to do that, you're going to have to capture all the
interesting lines in their own variables, and then print them in the desired
order outside of the while loop.
Gary
|
Title: Message
- RE: Parsing pids from drwtsn.log Gary MacDonald
- RE: Parsing pids from drwtsn.log Nikko Odiseos
- RE: Parsing pids from drwtsn.log Gary MacDonald
- RE: Parsing pids from drwtsn.log Brim, Robert
