a bit safer now
you can't move 2 files to the same target anymore
This commit is contained in:
parent
fefa3624ee
commit
e78a149ecb
1 changed files with 17 additions and 1 deletions
|
|
@ -46,7 +46,11 @@ close ($target);
|
|||
if ($DEBUG) { print @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;
|
||||
|
|
@ -62,3 +66,15 @@ while ( $i < scalar(@source) ) {
|
|||
}
|
||||
$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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue