#!/usr/bin/perl my $debug = 0; my $fverbose = 0; sub usage { die "Usage: $0 [-v][-d] "; } usage if (scalar @ARGV < 2); while ($_ = $ARGV[0], /^-/) { shift; if (/^-d(.*)/) { $debug = 1 || $1 } if (/^-v/) { $verbose++ } } my ($dir1, $dir2) = ($ARGV[0], $ARGV[1]); sub debug { return unless $debug; print @_; } debug "Source dir: $dir1\nTarget dir: $dir2\n"; add_to_hash($dir1, \%d1files); add_to_hash($dir2, \%d2files); foreach $key (keys %d1files) { if (! exists $d2files{$key}) { debug "$key: Skipping: $d1files{$key}\n"; next; } debug "$key: Match: $d1files{$key} Delete: $d2files{$key}\n"; if (! $debug) { unlink $d2files{$key} or warn "Could not unlink $defiles{$key}: $!"; print "Deleted: $d2files{$key}\n" if ($verbose); } } sub add_to_hash { my ($dir,$href) = @_; my ($dh, $base); opendir($dh, $dir) || die "can't open $dir: $!"; while(readdir $dh) { next if /^\./; ($base = $_) =~ s/(\d{8})[^.]*(\..+)$/\1*\2/; $href->{$base} = "$dir/$_"; debug "$href->{$base}\n"; } closedir $dh; }