| Next | Program
Repair Shop ![]() |
78 |
23 if (! -d $dst && -e $dst) {
24 die "Can't continue because a file has target's dir name\n";
25 } elsif ( ! -e $dst ) {
26 mkdir $dst or die "Couldn't create dir : $target_node\n";
27 }
Here we have repeated code---the -e $dst
In this case we can fix it by permuting the program logic a little:
if (-e $dst) {
die "Can't continue because a file has target's dir name\n"
unless -d $dst
} else {
mkdir $dst or die "Couldn't create dir : $target_node\n";
}
For the -d and -e file tests there's yet another shortcut
-X _ means to do the test on the same file that was tested last time
This saves execution time and reading time:
if (-e $dst) {
die "Can't continue because a file has target's dir name\n"
unless -d _;
} else {
mkdir $dst or die "Couldn't create dir : $target_node\n";
}
| Next | ![]() |
Copyright © 2002 M. J. Dominus |