Skip to content

Commit 06ea94a

Browse files
authored
which: retire dir-separator variable (#877)
* As done in other scripts, join filename to base directory with catfile() because it abstracts some OS details * Now the global $file_sep can be removed * I didn't test this on Mac OSX or old MacOS, but I expect catfile() won't do any harm for OSX case
1 parent 0cd97dc commit 06ea94a

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

bin/which

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ License: perl
1414
use strict;
1515

1616
use File::Basename qw(basename);
17+
use File::Spec;
1718
use Getopt::Std qw(getopts);
1819

1920
use constant EX_SUCCESS => 0;
2021
use constant EX_PARTIAL => 1;
2122
use constant EX_FAILURE => 2;
2223

2324
my $Program = basename($0);
24-
my ($VERSION) = '1.4';
25+
my ($VERSION) = '1.5';
2526

2627
sub usage {
2728
warn "$Program version $VERSION\n";
@@ -36,7 +37,6 @@ getopts('a', \%opt) or usage();
3637
my @PATH = ();
3738
my $PATHVAR = 'PATH';
3839
my $path_sep = ':';
39-
my $file_sep = '/';
4040
my @PATHEXT = ();
4141

4242
my $Is_DOSish = ($^O eq 'MSWin32') ||
@@ -51,7 +51,6 @@ if ($^O eq 'MacOS') {
5151
$PATHVAR = 'Commands';
5252
# since $ENV{Commands} contains a trailing ':'
5353
# we don't need it here:
54-
$file_sep = '';
5554
}
5655

5756
# Split the path.
@@ -74,7 +73,6 @@ if ($^O eq 'VMS') {
7473
$i++;
7574
}
7675
# PATH and DCL$PATH are likely to use native dirspecs.
77-
$file_sep = '';
7876
}
7977

8078
# trailing file types (NT/VMS)
@@ -110,7 +108,7 @@ foreach my $command (@ARGV) {
110108
next COMMAND if $found;
111109

112110
foreach my $dir (@PATH) {
113-
my $path = $dir . $file_sep . $command;
111+
my $path = File::Spec->catfile($dir, $command);
114112

115113
if (-d $path) {
116114
next;

0 commit comments

Comments
 (0)