http://www.perlmonks.org?node_id=924106

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

Hello illuminated ones,

I have the following problem:

My Perl script uses a local file as a database for some task. The file is nothing fancy - just a plain ASCII file with entries separated by empty lines. The master copy of this file is available on the Web. I would like to make sure that my local copy is up-to-date - i.e., matches the master copy.

Is there a CPAN module or something for that sort of task - or do I have to re-invent the wheel? The task seems basic enough to me, so I thought that probably somebody has already solved it before - but I couldn't find anything useful...

  • Comment on Keeping a local copy of a file up-to-date

Replies are listed 'Best First'.
Re: Keeping a local copy of a file up-to-date
by Jim (Curate) on Sep 04, 2011 at 18:36 UTC

    Consider using the simple, procedural module LWP::Simple and its mirror() function. It will allow you to download a replacement copy of the flat file database table (the ASCII text file) only when it has changed since the last time your Perl script downloaded it.

      This seems to do the job, thanks!
Re: Keeping a local copy of a file up-to-date
by BrowserUk (Patriarch) on Sep 04, 2011 at 21:22 UTC

    The lwp-mirror command that comes with perl is for exactly this task.

    lwp-mirror [-v] [-t timeout] <url> <local file>

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Keeping a local copy of a file up-to-date
by chrestomanci (Priest) on Sep 04, 2011 at 21:01 UTC

    Is the sending file on a public web server, or a private one that you control?

    If it is a private server you can control, and it runs linux, then check out lsyncd, which piggybacks on rsync and the kernel file change callback hooks to keep files in sync between two machines.