Rob Dixon wrote:
> Perl wrote:
> > I am attempting to parse a log file that looks something like:
> >
> > 759033281 TE18 <Vups_MsgStore> constructor - add to MDBTable
> > EX:/O=MSGENG/OU=EUROPE/CN=RECIPIENTS/CN=PHARWOOD
> > 759033281 TE18 <Vups_MsgStore> AddRef=2
> > EX:/O=MSGENG/OU=EUROPE/CN=RECIPIENTS/CN=PHARWOOD
> > 759033281 TE18 <MSM> S-REXCH-MSG-07
> > 759033281 TE18 <MSM> S-REXCH-MSG-06
> > 759033281 TE18 <MSM> C-REXCH-MSG-07
> > 759033281 TE18 <MSM> C-REXCH-MSG-06
> > 759033281 TE18 <VUPSMAPI> Vups_MailboxLogon done 0x0
> > 759033281 TE18 <MSM> C-REXCH-MSG-06
> > 759033281 TE18 <MSM> No timestamp for thread
> > 759033281 TE18 <MsgLog>     IMAPISession::OpenMsgStore          M
> > 109 Q      0
> >
> >
> > The only lines I am interested in are ones that have "PHARWOOD"
> > followed by a line that has "OpenMsgStore" in it.
> >
> > If I could explain this in English, I would want to say:
> >
> > "Search for an instance of "PHARWOOD" and once found print that
> > line. Then search for the very next instance of "OpenMsgStore"
> > that follows PHARWOOD (whether it be the next line or several
> > lines down) and print that."
> >
> >
> >
> > The code I have so far works but I don't understand how to change
> > my Regex filter to change from PHARWOOD to OpenMsgStore and back
> > again. Or is there a simpler method?
> >
> > Any help welcome,
> >
> > --Paul
> >
> >
> > -------------------------------
> >
> > $umlogs = "z\:";
> > opendir (DIR, "$umlogs") || die "Unable to open $umlogs
> > because:\n$!\n"; @dirs = readdir(DIR);
> > foreach $dir (@dirs) {
> > if ($dir =~/^V_DEBUG/i) {
> >
> >
> > open (LOGFILE, "$umlogs\\$dir") || die "unable to open $dir
> > because:\n$!\n";
> >
> > print "$umlogs\\$dir\n";
> > while (<LOGFILE>) {
> > my @fields = split / /;
> >
> >
> > if (/PHARWOOD/) {
> >
> > print $_;
> >
> >
> > }
> > }
> > }
> >
> >
> > }
>
> This loop does what you ask
>
>   print if /PHARWOOD/ .. /OpenMsgStore/ while <LOGFILE>;
>
> but if your input looks like
>
>
>   PHARWOOD
>     :
>   PHARWOOD
>     :
>   OpenMsgStore
>
> then it will print the whole sequence, not just those lines
> starting at the second 'PHARWOOD'. Is that what you want?
>

I'll get it right this time!

The loop needs to be

  while (<LOGFILE>) {
    print if /PHARWOOD/ ... /OpenMsgStore/;
  }

as you can't modify a statement with both an if .. and a while ..

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to