5

I was on Perlmonks and found this great listing:

http://www.perlmonks.org/?node_id=627015

But it was missing "which", the function that searches for an executable in all the directories in your PATH. (I am porting a Perl script to Windows.)

Is there a Perl module that simulates this?

1
  • There's also a which in PerlPowerTools, and I have my own tool I call rhich that's does a similar job but with regexes to match programs. Commented Jan 22, 2021 at 11:59

2 Answers 2

18

File::Which. Always check CPAN! :)

3
  • Thanks. Google failed me because "which" is a common word and all I got was garbage from my searches. Commented Aug 5, 2009 at 13:14
  • Well, why use Google when you can use CPAN Search (search.cpan.org). It's very hard to easily find things at www.cpan.org. Commented Aug 6, 2009 at 7:25
  • The File::Which::which doc says that it is a "Perl implementation of the which utility as an API". However, with version 1.09, calling File::Which::which("/bin/ls") returns undef. Calling "which /bin/ls" from a *nix shell returns "/bin/ls". Commented Jun 13, 2019 at 15:24
3

Have you seen this Snippet?

which (for Windows) in pure perl

The follow-up points to the module File::Which on CPAN.

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.