p.s. Apparently -x doesn't work for DLL files. Not so nice.
# input: # my $f = 'perl'; # for example # via command line: my $f = shift; # output: my @exec; { use File::Spec; my @ext = split /;/, $ENV{PATHEXT} || '.exe;.com;.bat'; foreach my $p (File::Spec->path) { push @exec, grep { -f and -x } map File::Spec->catfile($p, "$f +$_"), '', @ext; # You may leave the loop when something is found, if you only +care about the first } @exec or die "Can't find executable $f"; } # Show result: { local $\ = "\n"; print for @exec; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: `which` (for Windows) in pure perl
by salva (Canon) on Apr 22, 2006 at 21:44 UTC | |
by bart (Canon) on Apr 23, 2006 at 21:09 UTC | |
by jwkrahn (Abbot) on Apr 23, 2006 at 21:20 UTC | |
by tye (Sage) on Apr 24, 2006 at 14:53 UTC |