24 Jun 2002 21:21:05 UTC
- Distribution: File-Which
- Module version: 0.05
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (0)
- Testers (1060 / 3 / 0)
- KwaliteeBus factor: 1
- License: unknown
- Activity24 month
- Download (7.09KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version
- Steps Used on Win32, DOS, OS2 and VMS
- Bugs and Caveats
- See Also
File::Which - Portable implementation of the `which' utility
use File::Which; # exports which() use File::Which qw(which where); # exports which() and where() my $exe_path = which('perldoc'); my @paths = where('perl'); - Or - my @paths = which('perl'); # an array forces search for all of them
File::Whichwas created to be able to get the paths to executable programs on systems under which the `which' program wasn't implemented in the shell.
File::Whichsearches the directories of the user's
PATH(as returned by
File::Spec->path()), looking for executable files having the name specified as a parameter to
which(). Under Win32 systems, which do not have a notion of directly executable files, but uses special extensions such as
.batto identify them,
File::Whichtakes extra steps to assure that you will find the correct file (so for example, you might be searching for
perl, it'll try
Windows NT has a special environment variable called
PATHEXT, which is used by the shell to look for executable files. Usually, it will contain a list in the form
File::Whichfinds such an environment variable, it parses the list and uses it as the different extensions.
This set of operating systems don't have the
PATHEXTvariable, and usually you will find executable files there with the extensions
.batand (less likely)
File::Whichuses this hardcoded list if it's running under Win32 but does not find a
Same case as Windows 9x: uses
.com(in that order).
Exported by default.
$short_exe_nameis the name used in the shell to call the program (for example,
If it finds an executable with the name you specified,
which()will return the absolute path leading to this executable (for example,
If it does not find the executable, it returns
which()is called in list context, it will return all the matches.
Not exported by default.
which($short_exe_name)in array context. Same as the
`where'utility, will return an array containing all the path names matching
Not tested on VMS or MacOS, although there is platform specific code for those. Anyone who haves a second would be very kind to send me a report of how it went.
File::Spec adds the current directory to the front of PATH if on Win32, VMS or MacOS. I have no knowledge of those so don't know if the current directory is searced first or not. Could someone please tell me?
Per Einar Ellefsen, <per.einar (at) skynet.be>
Originated in modperl-2.0/lib/Apache/Build.pm. Changed for use in DocSet (for the mod_perl site) and Win32-awareness by me, with slight modifications by Stas Bekman, then extracted to create
Version 0.04 had some significant platform-related changes, taken from the Perl Power Tools
`which'implementation by Abigail with enhancements from Peter Prymmer. See http://www.perl.com/language/ppt/src/which/index.html for more information.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.