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

Hi Monks, I have two text files in different directories. I constantly have to update the two files. Is there a way to have a perl script to read both files and synchronize one with the most recent one? Thank you!!!!!

Replies are listed 'Best First'.
Re: Text File Synchronization
by svsingh (Priest) on Oct 09, 2003 at 00:41 UTC
    If they serve the same purpose, then would it be possible to just use one file? I'm thinking of the adage, "A man with one watch always knows the time. A man with two is never sure."

    Otherwise, I think we need to know a bit more about the files to know how to handle certain issues. For example, what if they're config files and File A has one setting and B has another? How would you want to synchronize that?

Re: Text File Synchronization
by BrowserUk (Patriarch) on Oct 09, 2003 at 00:51 UTC

    This should be pretty platform independant.

    perl -mFile::Copy=copy -e" copy @ARGV[ -s $ARGV[0] > -s $ARGV[1] ? ( 0 +, 1 ) : ( 1, 0 ) ]" \path\to\file1 \path\to\file2

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail