Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: New Perl programmer looking for answer in Directory Comparisons

by lindex (Friar)
on May 01, 2001 at 21:05 UTC ( #77028=note: print w/ replies, xml ) Need Help??


in reply to New Perl programmer looking for answer in Directory Comparisons

This is my "There's more than one way to do it", its prolly insane and stupid. But I did it anyways.

p.s. some borrowed methodology from merlyn.

#!/usr/bin/perl -w use strict; use File::Copy qw(copy); die("Usage: $0 <src> <dst>\n") unless($#ARGV==1); -d or die("$_ is not a directory") for(@ARGV); s/\/$// for(@ARGV); for(glob("$ARGV[0]/*"),glob("$ARGV[1]/*")) { copy("$ARGV[0]/$_","$ARGV[1]/$_") or warn("$!: $ARGV[0]/$_\n") if(s/$ARGV[0]// && -f "$ARGV[0]/$_" && !-e "$ARGV[1]/$_"); unlink("$ARGV[1]/$_") or warn("$! unlinking $ARGV[1]/$_\n") if(s/$ARGV[1]// && -f "$ARGV[1]/$_" && !-e "$ARGV[0]/$_" ); }



lindex
/****************************/ jason@gost.net, wh@ckz.org http://jason.gost.net /*****************************/


Comment on Re: New Perl programmer looking for answer in Directory Comparisons
Select or Download Code
Re: Re: New Perl programmer looking for answer in Directory Comparisons
by merlyn (Sage) on May 01, 2001 at 21:10 UTC
    Well, stealing from that:
    use File::Copy; use File::Basename; for $base (map basename $_, map glob "$_/*", @ARGV) { my ($src, $dst) = map "$_/$base", @ARGV; -f $src and not -e $dst and not copy $src, $dst and warn "copy $src +to $dst failed"; -f $dst and not -e $src and not unlink $dst and warn "unlink $dst fa +iled: $!"; }

    -- Randal L. Schwartz, Perl hacker

      Hmm, I wonder if I can make it any shorter ;)
      foiled agian, Yarr


      lindex
      /****************************/ jason@gost.net, wh@ckz.org http://jason.gost.net /*****************************/

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://77028]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (17)
As of 2014-09-18 14:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (116 votes), past polls