Nik has asked for the wisdom of the Perl Monks concerning the following question:

Hello, in my website i have a perl script that logs all the traffic in as single file called log.txt !!! the file looks liek this:
localhost -> Tue Apr 6 07:50 localhost -> Tue Apr 6 07:51 -> + ChickenInvaders localhost -> Tue Apr 6 07:51 localhost -> Tue Apr 6 07:52 -> + BrainsBreaker localhost -> Tue Apr 6 07:54
when the user enters index.pl his ip address is being logges along with the time. Problem is that when the user goes to games.pl then he logger puts one more record to the log.txt telling me that the user also gone to games.pl and it gives me the file he doewnloaded.
What i want is if the user enter games.pl and downloads the file i want the same record inside log.txt to be updated and put a filed aside telling me what was the file that he downloaded!! here is the script of the log:
open(OUT, ">>../data/texts/log.txt") or die $!; print OUT $host, " "x(40-length($host)), "-> ", $xronos, "\n"; close(OUT); and the the log also inside games.pl <code> open(OUT, ">>../data/texts/log.txt") or die $!;print(OUT $host, " "x(4 +0-length($host)), "-> ", $xronos, " -> ", $game, "\n"); close(OUT);
can you help me out?!?

Replies are listed 'Best First'.
Re: Text file Update problem!
by Zaxo (Archbishop) on Apr 08, 2004 at 18:10 UTC

    I think you want to print conditionally. The trinary op is helpful:

    print OUT $host, " "x(40-length($host)), "-> ", $xronos, (defined $game ? " -> $game" : ''), "\n";
    That handles both cases.

    After Compline,
    Zaxo

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Text file Update problem!
by chip (Curate) on Apr 08, 2004 at 19:29 UTC
    "You can't get there from here." Updating text files in place is possible, but it's basically a matter of reading a bunch in and writing it all back out again, what with variable-length records. So I guess you should just post-process the log.

        -- Chip Salzenberg, Free-Floating Agent of Chaos

    A reply falls below the community's threshold of quality. You may see it by logging in.