home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / contrib / edb / move-if-changed < prev    next >
Encoding:
Text File  |  1999-06-05  |  618 b   |  33 lines

  1. #!/usr/local/bin/perl
  2. if ($#ARGV <= 0 ) {
  3.     die;
  4. } elsif($#ARGV == 1 && -f $ARGV[0] && -f $ARGV[1]) {
  5.     &move_if_changed($ARGV[0],$ARGV[1]);
  6. } else {
  7.     $target_dir = pop(@ARGV);
  8.     while ($f = shift(@ARGV)) {
  9.     &move_if_changed($f, "$target_dir/$f");
  10.     }
  11. }
  12.  
  13. sub move_if_changed {
  14.     my($s,$t) = @_;
  15.     if(-f $s) {
  16.     if( -f $t) {
  17.         if(-M $s < -M $t) { 
  18.         if(system("cmp -s $s $t")) {
  19.             print "move $s $t\n";
  20.             rename($s,$t);
  21.         } else {
  22.             #print "$t is not changed\n";
  23.         }
  24.         } else {
  25.         #print "$s is older than $t\n";
  26.         }
  27.     } else {
  28.         print "move $s $t\n";
  29.         rename($s,$t);
  30.     }
  31.     }
  32. }
  33.