Thanks for providing your code, but it's very hard to read without formatting. Please use 'code' tags as described in Writeup Formatting Tips, as follows:
while (<$fhlog>)
{
my $line = $_;
my $bufferline;
if ($line =~ /Finished (.*)\. Wrote (\d+) new, (\d+) duplicates, (
+\d+) archived/)
{
&storeAdapterDetails($1, $2, $3, $4, $fhresult);
next;
}
if ($line =~ /ERROR/)
{
$bufferline = '$line';
next;
}
if ($line =~ /.*Exception:/)
{
print "Found adapter: ".$bufferline; $flag = 1;
}
Some comments:
- $bufferline is declared inside the while loop, so any values assigned to it in one iteration will not be available in subsequent iterations (or after the loop is complete).
- Calling storeAdapterDetails with a leading '&' has consequences (see perlsub). Did you use it intentionally? If not, you may want to remove it to avoid potential bugs in the future.
- $fhresult is not declared in your example; I assume it is set prior to the loop
- Single quotes do not interpolate, so $bufferline is getting set to the literal string '$line'. You probably want $bufferline = $line; instead.
- Using 'next' after assigning to $bufferline prevents evaluation of the following if statement, so the print statement containing $bufferline will not be executed. Furthermore, when that statement is executed, $bufferline will be uninitialized.
- $flag is not declared in the loop, so I assume it was declared previously
- Using sequential 'if' statements implies (to me) that it is possible for more than one condition to apply during each iteration. If that is not the case (based on the use of 'next'), 'elsif' may convey more meaning to anyone reading the code.
- There is nothing wrong with while( <$fhlog> ) { my $line = $_; ... }, but I would write that as while( my $line = <$fhlog> ) { ... }
Hope this helps
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.