Simple copy script called mycopy.pl

Discussion in 'Perl Misc' started by Leander Jedamus, Oct 4, 2012.

  1. Leander Jedamus, Oct 4, 2012
    #1
    1. Advertising

  2. Am 04.10.2012 19:57, schrieb Ben Morrow:
    >
    > Quoth Leander Jedamus <>:
    >>
    >> I just wrote a simple script to fit my needs to copy from a SD-Card only
    >> those photos which are newer then a timestamp-file.
    >> Use at your on risk!
    >>
    >> It can be found at
    >> http://paste.ubuntu.com/1259875/

    >
    > - Use Term::ANSIColor rather than rolling your own.
    >
    > - Don't call subs with '&' unless you need to.
    >
    > - 'warn' is a builtin. Defining a sub with that name is a bad idea.
    >
    > - `date -r` is not portable (on my system it does something quite
    > different). Use stat() and POSIX::strftime.
    >
    > - This
    >
    > sub mycopy
    > {
    > my $sdir = $_[0];# source dir
    > my $ddir = $_[1];# destination dir
    > my $sfiles = $_[2];# the files to copy
    > my $rekursive = $_[3];# if going recursive? (y/n)
    > my $use_stamp = $_[4];# use stamp? (y/n)
    > my $stamp = $_[5];# the stamp
    > my $warn = $_[6];# warn level
    > my $debug = $_[7];#
    >
    > is a horrid mess. Learn how to use list assignment.
    >
    > - mkdirhier is not portable (it's part of X, from the bad old days when
    > mkdir didn't always understand -p). Use 'mkdir -p' (which ought to be)
    > or File::path (which definitely is).
    >
    > - I can't follow the logic in 'mycopy' at all. It must be possible to
    > write it without quite so many layers of ifs.
    >
    > - I don't think there is a single comment in that program which makes
    > anything clearer. Something like a general description of the logic
    > implemented by the twisty maze of ifs in mycopy would have been much
    > more useful than closing every sub with '};# sub foo'.
    >
    > - Use multi-arg system
    >
    > system "cp", "-p", $sfile, $dfile;
    >
    > rather than trying to get shell quoting right. What if there's a file
    > with " in its name?
    >
    > After that I got bored, but is this really doing anything you can't do
    > with find -newer | xargs cp ? Or just forget the stamps and use rsync.
    >
    > Ben
    >


    Thanks! I will look into it.

    Grüße
    Leander Jedamus
     
    Leander Jedamus, Oct 5, 2012
    #2
    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. Apricot
    Replies:
    4
    Views:
    560
    velthuijsen
    Apr 16, 2004
  2. Alex
    Replies:
    2
    Views:
    1,287
  3. Replies:
    26
    Views:
    2,175
    Roland Pibinger
    Sep 1, 2006
  4. Weng Tianxiang
    Replies:
    6
    Views:
    605
    glen herrmannsfeldt
    Sep 12, 2007
  5. Radu
    Replies:
    7
    Views:
    731
    charlie_Stell
    Aug 28, 2009
Loading...

Share This Page