Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Keeping a local copy of a file up-to-date

by bontchev (Sexton)
on Sep 04, 2011 at 18:11 UTC ( #924106=perlquestion: print w/ replies, xml ) Need Help??
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
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 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.

Re: Keeping a local copy of a file up-to-date
by BrowserUk (Pope) 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.

      bontchev plainly asked:

      My Perl script uses a local file as a database for some task. 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 for that sort of task - or do I have to re-invent the wheel?

      How is information about a command-line utility relevant to Dr. Bontchev's inquiry about a CPAN module for use in his Perl script?

        Because if you look inside that script, ignoring the command line options and help stuff, the whole script consists of two lines:

        use LWP::Simple qw( mirror ); $rc = mirror( $url, $file );

        'nuff said?


        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.
Reaped: Re: Keeping a local copy of a file up-to-date
by NodeReaper (Curate) on Sep 05, 2011 at 13:47 UTC
Reaped: Re: Keeping a local copy of a file up-to-date
by NodeReaper (Curate) on Sep 06, 2011 at 14:11 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://924106]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2014-11-26 15:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (171 votes), past polls