Hi Monks!,

I have a log file that I am wanting to search for the current date and if you finds the current date in the file with a error, capture the line with date and time. The problem I have is that it will print several or hundreds of lines because the file will contain many lines with the date and time. That said, I just want to send a message with the ONE line when it encounters an API error on that particular date.
Example: Log File Line Containing Date [1/21/2008 4:33 AM] API call error
print "\n"; print "======================================\n"; $aDate = &get_cur_time; print "=====================================\n"; open(FH, "c:\sync.log") || die "Cannot open Log:$!\n"; while (<FH>) { if ($aDate) { print "ERROR\n"; } }; close(FILE); print "\n"; ### Getting a time format for printing ### sub get_cur_time { my $Second; my $Minute; my $Hour; my $Day; my $Month; my $Year; my $WeekDay; my $DayOfYear; my $IsDST; ($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time); my $RealMonth = $Month + 1; $RealMonth = "0" . $RealMonth if($RealMonth < 10); $Day = "0" . $Day if($Day < 10); $Hour = "0" . $Hour if($Hour < 10); $Minute = "0" . $Minute if($Minute < 10); $Second = "0" . $Second if($Second < 10); my $Fixed_Year = $Year + 1900; ### Making Date Format For Files ### #return "$RealMonth$Day$Fixed_Year"; ### Different Format ### print "Today's Date is: $RealMonth/$Day/$Fixed_Year $Hour:$Minute:$Sec +ond\n"; };

In reply to Reading log file for current date by raj8

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.