in reply to copy excel sheets to a different workbook

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^2: copy excel sheets to a different workbook
by MidLifeXis (Monsignor) on Nov 11, 2008 at 13:35 UTC
    • This will not compile. You are missing quotes around the argument to system.
    • Unless the syntax of cp has changed in Linux, you would want that to be: 'cp *.xls /newdir/.'.
    • Why use perl for this, you are just spawning another interpreter? (However, see moritz's point below)
    • See File::Copy
    • It does not answer the question posed by the OP. More analogous (although not correct) would be cat *.xls > newdir/newfile.xls

    Update: Add last point, remove recursive flag from cp command.

    Update: Note moritz's most excellent point.

    --MidLifeXis

      While your points are good and valid, I'd like to point out there is is a good reason to invoke cp via system instead of using File::Copy: The latter doesn't preserve file permissions on Unix and Linux.

      (Actually that's pretty sad for such an old piece of software. There's been a thread about that on p5p during the last few months, but I don't recall what the result was, if any.)

        While your points are good and valid, I'd like to point out there is is a good reason to invoke cp via system instead of using File::Copy: The latter doesn't preserve file permissions on Unix and Linux.

        I personally believe this is very well known, with Abigail often advocating its use. Another issue I've "always" been wondering about has to do with sparse files: if I create one and then copy it with cp, IIRC the target file will also be sparse and a quick experiment now confirms my memory:

        1;0 blazar@feather:~/tmp$ perl -e 'open F, ">foo.txt"; seek F, 2**30, +0; print F 1' 1;0 blazar@feather:~/tmp$ ls -lh . ; du -sh . total 12K -rw-r--r-- 1 blazar blazar 1.1G Nov 16 10:22 foo.txt 16K . 1;0 blazar@feather:~/tmp$ time cp foo.txt bar.txt && echo -e "\a" real 0m2.357s user 0m0.204s sys 0m2.064s 1;0 blazar@feather:~/tmp$ ls -lh . ; du -sh . total 24K -rw-r--r-- 1 blazar blazar 1.1G Nov 16 10:22 bar.txt -rw-r--r-- 1 blazar blazar 1.1G Nov 16 10:22 foo.txt 28K .

        It takes some time (which further increases with the size of the file) and I don't have the slightest idea of how it manages to do so... (perhaps some fiddling with strace(1) may help, but I should be more confident with it.) But it succeeds. How does File::Copy behave in this respect? I believe it will create a file with an actual disk usage comparable to its own size, filled with nulls, ain't it?

        Granted, I would regard this as a minor but not completely irrelevant issue.

        --
        If you can't understand the incipit, then please check the IPB Campaign.
Re^2: copy excel sheets to a different workbook
by sagnal (Initiate) on Nov 12, 2008 at 06:52 UTC
    cp would not work for me as I do not want to make copy of the existing workbooks. I want to copy a few sheets from (two) different workbooks to a new workbook.