in reply to Re: Parse Log File As Written
in thread Parse Log File As Written

"Changes to the array are reflected in the file immediately."

Note that the Tie::File docs do not say here (or anywhere else) that changes to the file will be reflected in the array immediately. Tie::File may be capable of following additions to a ever-growing file, but that really doesn't appear to be one of the tasks it was designed to handle.

A couple more relevant bits from the locking section of the Tie::File docs are

When you use flock to lock the file, Tie::File assumes that the read cache is no longer trustworthy, because another process might have modified the file since the last time it was read. Therefore, a successful call to flock discards the contents of the read cache and the internal record offset table.

and

The best way to unlock a file is to discard the object and untie the array.

To me, these indicate that, if the underlying file is changed, then Tie::File will have to rebuild its table of record offsets, which means starting over from the beginning of the file and reading every line until it reaches the one you're looking for (i.e., the one that was just added to the end of the file), which is exactly the sort of re-scan we're trying to avoid here.

Replies are listed 'Best First'.
Re^3: Parse Log File As Written
by atemon (Chaplain) on Sep 24, 2007 at 17:34 UTC

    "Changes to the array are reflected in the file immediately."

    This is something I copied from CPAN's Tie::File. it IS the 3rd line of the description.

    The CPAN doc gives other caveats of Tie::File

    Cheers !

    --VC



    There are three sides to any argument.....
    your side, my side and the right side.

      Yes, I saw it there. I didn't dispute that the docs say the array immediately updates the file. However, they do not say that the file immediately updates the array. Array -> file does not imply file -> array.