I am attempting to pull a number (in my example 1530631) from a line before the line with the beep. * Line that needs to be matched, and I need 1530631. (8/20/09 7:59:28 PM EDT) 1530631: ^^5 * Than I need to match this line and pull this number 1531639. (8/20/09 7:59:28 PM EDT) 1531639: ##Twenty Four;##;pp * I will take the two numbers and subtract them from each other. My current code can only pull the line with the beep, but i cannot figure how to match the line before the beep.
# open a file my $filename = $ARGV[0]; open(debugfile, $filename) || die "Sorry, couldn't open file!"; while($line = <debugfile>) { if($line =~ /##BEEP/) # place the regular expression to match the +first line here { print $line; @firstLine = split(/\)/, $line); $firstLineTime = $firstLine[1]; @match = split (/##/, $firstLineTime); $Tic = $match[0]; $waitingForTargetStatement = 1; # print "$firstLineTime\n"; # print "$Tic\n"; next; } if($line =~ /Pick/ && $waitingForTargetStatement == 1) # place the + regular expression to match the second line here { $waitingForTargetStatement = 0; @secondLine = split(/\)/, $line); $secondLineTime = $secondLine[1]; @match = split (/##/, $secondLineTime); $Tic = $match[0]; $time = $secondLineTime - $firstLineTime; $time = $time/1000; print $line; # print "$Tic\n"; print "The time between the beep and the next pick location is + $time seconds\n"; # modify the print statement print "\n"; next; } # if($line =~ /##|\^\^|SYSMSG|DIALOG/) # place a regular expression + to include other desired content here. # { # print $line; # } }
EXAMPLE OF LOG: (8/20/09 7:59:28 PM EDT) 1524243: ##BEEP (375,2)## (8/20/09 7:59:28 PM EDT) 1524516: ##Two;Five; Pick (8/20/09 7:59:28 PM EDT) 1530337: ^^7 (8/20/09 7:59:28 PM EDT) 1530631: ^^5 (8/20/09 7:59:28 PM EDT) 1531465: ##BEEP (375,2)## (8/20/09 7:59:28 PM EDT) 1531639: ##Twenty Four;##;pp (8/20/09 7:59:44 PM EDT) 1534041: ^^ready (8/20/09 7:59:44 PM EDT) 1534177: ##Three;One; Pick (8/20/09 7:59:44 PM EDT) 1540464: ^^8 (8/20/09 7:59:44 PM EDT) 1540760: ^^8 (8/20/09 7:59:44 PM EDT) 1541590: ##BEEP (375,2)## (8/20/09 7:59:44 PM EDT) 1541884: ##Two;Three; Pick

In reply to How to match previous line by qnguyen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.