How to copy a file and force overwirte in perl

Discussion in 'Perl Misc' started by Jay@HK, Nov 30, 2006.

  1. Jay@HK

    Jay@HK Guest

    I have to write a perl script to copy and overwrite a file,
    I tried to use file::copy but it seems no options for force overwrite
    the destination file.
    please advise.

    Thanks!
    Jay@HK, Nov 30, 2006
    #1
    1. Advertising

  2. Jay@HK

    Paul Lalli Guest

    Jay@HK wrote:
    > I have to write a perl script to copy and overwrite a file,
    > I tried to use file::copy but it seems no options for force overwrite
    > the destination file.
    > please advise.


    What are you talking about? File::Copy *does* overwrite the
    destination file.

    $ cat > file1.txt
    THIS IS FILE ONE
    $ cat > file2.txt
    this is the second file
    $ perl -MFile::Copy -e'copy "file1.txt", "file2.txt"'
    $ cat file2.txt
    THIS IS FILE ONE
    $

    Paul Lalli
    Paul Lalli, Nov 30, 2006
    #2
    1. Advertising

  3. Jay@HK

    Dr.Ruud Guest

    Jay@HK schreef:

    > I have to write a perl script to copy and overwrite a file,
    > I tried to use file::copy but it seems no options for force overwrite
    > the destination file.
    > please advise.


    s/file::copy/File::Copy/

    --
    Affijn, Ruud

    "Gewoon is een tijger."
    Dr.Ruud, Nov 30, 2006
    #3
  4. Jay@HK

    Stan R. Guest

    Paul Lalli wrote:
    > Jay@HK wrote:
    >> I have to write a perl script to copy and overwrite a file,
    >> I tried to use file::copy but it seems no options for force overwrite
    >> the destination file.
    >> please advise.

    >
    > What are you talking about? File::Copy *does* overwrite the
    > destination file.
    >
    > $ cat > file1.txt
    > THIS IS FILE ONE
    > $ cat > file2.txt
    > this is the second file
    > $ perl -MFile::Copy -e'copy "file1.txt", "file2.txt"'
    > $ cat file2.txt
    > THIS IS FILE ONE
    > $
    >
    > Paul Lalli


    It's most like a permissions problem (which is why it's always good to
    check return statuses & $!)

    --
    Stan
    Stan R., Dec 1, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex
    Replies:
    2
    Views:
    1,224
  2. Replies:
    26
    Views:
    2,113
    Roland Pibinger
    Sep 1, 2006
  3. Martin Martinos

    How to force a copy over a read-only file

    Martin Martinos, Jan 15, 2008, in forum: Ruby
    Replies:
    2
    Views:
    113
    Martin Martinos
    Jan 17, 2008
  4. Avi
    Replies:
    0
    Views:
    184
  5. MaggotChild

    File::Copy::copy With File Handles

    MaggotChild, Oct 18, 2011, in forum: Perl Misc
    Replies:
    2
    Views:
    505
    Ilya Zakharevich
    Oct 22, 2011
Loading...

Share This Page