Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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]/$_" ); }

/****************************/, /*****************************/

Replies are listed 'Best First'.
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

      /****************************/, /*****************************/

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://77028]
[choroba]: Why don't they use tire chains?
[perldigious]: First snow, probably not prepared right away choroba.
[stevieb]: it's Quebec... they do weird stuff there :) In the mountains, it is *mandatory* for trucks to use tire chains. Many passenger vehicles do as well (but it's not mandatory for them)
[perldigious]: That stuff can hit fast... like what we just got where I'm at. Saw a few people who had slid OUT of the roundabout I have to drive through to get to work, not used to the ice yet, take awhile to get the hang of it again and make vehicle adjustments.
[stevieb]: man, when the roads are glare ice, I don't even bother going to work or out... unless I absolutely have to, or was already out in the first place
[choroba]: Tire chains are mandatory here in mountains, and the only unprepared each year are gritters
[stevieb]: I have a 3 day winter survival kit in my vehicle in the event I get snowed in in the mountains (which has happened before due to avalanches closing the roads (and once in the summer due to a massive forest fire that trapped us
[perldigious]: a handful of people in my work area did not make it, but I live pretty close and it's flat the whole way, so I didn't have any trouble. The roundabout is the worst thing I have to negotiate.
[thezip]: G'day all!
[perldigious]: Well, that and dodging the people who forget how ice works right away. :-)

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2016-12-06 16:38 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (112 votes). Check out past polls.