I'm not familiar with File::ReadBackwards, but the core of your handling (and most likely location for a problem) is
while( !$found && defined( my $log_line = $bw->readline ) ) { if ($log_line =~ /GET \/myapp\//) { $last_line = $log_line; $bw->close(); } }
This probably works reasonably well, given that you would expect $bw->readline to return undef after being closed, but a quick check of its docs on CPAN didn't turn up anything actually saying that it will. You're also wastefully checking $found on each iteration, even though there is nothing in the code you posted which ever sets it, aside from its initialization to 0 when declared.

To ensure that neither of these is causing problems, I would rewrite the loop as

while(defined( my $log_line = $bw->readline ) ) { if ($log_line =~ /GET \/myapp\//) { $last_line = $log_line; last; } } $bw->close();
This modification skips testing $found, explicitly exits the loop once it finds a match, and will always close $bw whether the file matches or not.

Within the loop itself, you can probably improve performance a fair bit by replacing the regex match with a call to substr, since you're looking for a static string and don't need the overhead introduced by the regex engine.

If it's still slow after all that, try setting up a second loop that does the same thing, but reading the file normally from start to end and storing only the last match. Comparing the time taken by the two versions could provide some clues as to where the problem is. (i.e., If they both take just as long, then File::ReadBackwards isn't doing its job very well.)


In reply to Re: Emulating command line pipe by dsheroh
in thread Emulating command line pipe by davistv

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.