Something else to consider but perhaps a little bit sloppy is to dump the
interesting lines into another file and then use _Total.exe as the end of
your string instead of \n.  This allows you to seperate the multiple entries
in the log into their own entity.  Then matching App pid to program pid
becomes easier.  You can probably clean this up some but this works for me.

$fh = "$ARGV[0]\\c\$\\winnt\\drwtsn32.log";
$log = "drwlog.txt";
open DRW, "$fh" || die "Can't open $fh for read: $!";
open LOG, ">$log" || die "Can't open $log for write: $!";

while (<DRW>)
{
  @result = grep /App:|When|\.exe/, $_;
  if (@result > 0)
  {
    print LOG "@result";
  }
}
close DRW; close LOG;

open LOG, "$log" || die "Can't open $log for write: $!";
$/ = "_Total.exe\n";
foreach $line (<LOG>)
{
  my ($app, $when, $exe, $appid);
  my @wrkdata = split /\n/, $line;
  foreach $data (@wrkdata)
  {
    if ($data =~ /App:/)
    {
      $app = $data;
      $app =~ s/^\s+//, $app;
      $app =~ s/exe.+\s/ /, $app;
      ($x, $appid) = split /=/, $data;
      $appid =~ s/\)//, $appid;
    }
    elsif ($data =~ /When:/)
    {
      $when = $data;
      $when =~ s/^\s+//, $when;
    }
    elsif ($data =~ /$appid/)
    {
      $exe = $data;
      $exe =~ s/^\s+\d+\s//, $exe;
    }
  }
  print "$app, $exe,  $when";
}
close LOG;



Date: Mon, 03 Dec 2001 13:03:38 -0700
From: Gary MacDonald <[EMAIL PROTECTED]>
Subject: RE: Parsing pids from drwtsn.log
To: [EMAIL PROTECTED]


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
 



_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin

Reply via email to