I've been playing around and testing for a while now ... What I've learned:

File::Tail does NOT work for Win32 systems.

The Tie::File method seems like it could work but I'm having problems with the code:
#!/perl use strict; use warnings; use Tie::File; my $logfile = "blablalogfile.txt"; #my $logfile = "test.txt"; my $o = tie my @array, 'Tie::File', $logfile; $o->flock; my $line_count = $#array; while (1) { if ($line_count < $#array) { $line_count++; # foreach my $line (@array) { foreach my $line ($line_count .. $#array) { print $line; } $line_count = $#array; } sleep(1); }
Basically, the program runs, and goes to the continuous loop as expected. The problem is that if the $o->flock; is there, the program won't update the log file, and even if I use a test text file and manually save the file, Windows won't allow it because another program has locked it. If I uncomment the lock (I'll never want to write to the log file, so is locking it even necessary?) then the loop never detects that the file is updated, which it is. I'm not familiar with the context used in the foreach loop in the example ... Will the '$line_count ... $#array' actually count in the @array if not specifically specified? Even going through all of @array upon a newline yields no output.

Thanks for all the help ... I don't know why but I always seem to make things difficult, and I might be going a bit crazy!

-Alan

Edit:Is Tie::File capable of watching changes to the file in realtime? I've noticed in the docs that the file updates as soon as the array is modified and written, but does the array update if the file is updated?

Edit 2:It seems that the $#array never updates to reflect the current number of lines in the file, without flock. With flock the file never updates so I can't determine if $#ever would update.

In reply to Re: Parse Log File As Written by alanonymous
in thread Parse Log File As Written by alanonymous

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.