Skip to content

Commit

Permalink
which: retire dir-separator variable
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mknos authored Dec 17, 2024
1 parent c2dbf20 commit 1d377c3
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions bin/which
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ License: perl
use strict;

use File::Basename qw(basename);
use File::Spec;
use Getopt::Std qw(getopts);

use constant EX_SUCCESS => 0;
use constant EX_PARTIAL => 1;
use constant EX_FAILURE => 2;

my $Program = basename($0);
my ($VERSION) = '1.4';
my ($VERSION) = '1.5';

sub usage {
warn "$Program version $VERSION\n";
Expand All @@ -36,7 +37,6 @@ getopts('a', \%opt) or usage();
my @PATH = ();
my $PATHVAR = 'PATH';
my $path_sep = ':';
my $file_sep = '/';
my @PATHEXT = ();

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

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

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

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

if (-d $path) {
next;
Expand Down

0 comments on commit 1d377c3

Please sign in to comment.