Re: Newbie: Find and replace events in log file

Discussion in 'Perl' started by Luuk, Jan 14, 2011.

  1. Luuk

    Luuk Guest

    On 14-01-11 01:27, Jack B. Pollack wrote:
    > I am a complete newbie to this but was able to cobble together a logging
    > script that takes my string passed to the script
    > ( and appends it to the end of a file. So
    > basically now I am creating a long text file of logged data.
    > This takes a long time to load into a browser as the file grows in size.
    > Since I am only logging about 20 decree events and don't care about the

    discrete ?

    > history, just the last occurrence, I would like to modify the script to
    > replace the previous event with the same name if it already exists (or add
    > it if it is new)
    > Eg.
    > Event id 1 1-5-11 5:30:00
    > Event id 7 1-4-11 9:20:20
    > Event id 2 1-7-11 4:21:56
    > Event id 6 1-2-11 8:21:30
    > New event:: Event id 7 1-12-11 4:56:22
    > This is currently getting tacked on to the bottom of the file. I would like
    > to detect that there is already an Event id 7 and replace it with the new
    > time stamp. Obviously if there is a new unique event I would like to append
    > it to the bottom of the file.

    When i had knowledg about perl, i would create an array, and store the
    date/time values in the array

    a[1]="1-5-11 05:30:00";
    a[2]="1-4-11 09:20:20";

    this way its 'easy' to store a new event
    if (newdate>a[7]) { a[7]=newdate; }

    But i'm a more complete newbie to perl than you ;)

    Luuk, Jan 14, 2011
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.