a bit safer now

you can't move 2 files to the same target anymore
This commit is contained in:
Ward Wouts 2001-07-31 09:18:48 +00:00
parent fefa3624ee
commit e78a149ecb

View file

@ -46,7 +46,11 @@ close ($target);
if ($DEBUG) { print @target; } if ($DEBUG) { print @target; }
unless ( scalar(@source) == scalar(@target) ) { unless ( scalar(@source) == scalar(@target) ) {
die "source and target don't have the same number of lines"; die "Aborting. Source and target list don't have the same number of lines.\n";
}
if (&check_unique(@target)) {
die "Aborting. You're trying to move multiple files to the same name.\n";
} }
$i=0; $i=0;
@ -62,3 +66,15 @@ while ( $i < scalar(@source) ) {
} }
$i++; $i++;
} }
# returns 0 if all entries in @target_list are unique. 1 if not.
sub check_unique (@target_list){
my(@target_list, %seen, @uniqu);
@target_list = @_;
%seen = ();
@uniqu = grep { ! $seen{$_} ++ } @target_list;
unless (scalar(@uniqu) == scalar(@target) ) {
return 1;
}
return 0;
}