http://qs321.pair.com?node_id=206586


in reply to Using OPEN to append to a file

have you tried using Tie::File it works great for me when reading and writing to files. Here is what I came up with:
#!perl use strict; use warnings; use Tie::File; my @log; my @archive; tie @log, 'Tie::File', "C:/WINDOWS/U.S. Robotics 56K Voice INT PnP.log +"; tie @archive, 'Tie::File', "H:/ppp_stats.log"; push @archive, @log; $#log = 0; pop @log; #otherwise the first line of the file #gets left there, untie @log; untie @archive;
I did acouple of test runs on small files and it worked for me, but you might want to run some test before using it as working code. Feel free to make any edits. I make no promise that this will work for you, but it worked when I ran it.

Update: I didn't put the use diagnostic in my code, I'm not sure what that does, I've never seen it before.

Update: as nothingmuch pointed out to me instead of finding the length of @log and subtracting that from $#log, I can just set $#log to 0, much easier :)

Update: now it won't leave the blank line in the log file, not sure if thats the best way to do it, but it works

jjdraco
learning Perl one statement at a time.