Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Text File Synchronization

by Anonymous Monk
on Oct 09, 2003 at 00:12 UTC ( [id://297772]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://297772]
Approved by jdtoronto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-19 04:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found