1Which(3)              User Contributed Perl Documentation             Which(3)
2
3
4

NAME

6       File::Which - Portable implementation of the `which' utility
7

SYNOPSIS

9         use File::Which;                  # exports which()
10         use File::Which qw(which where);  # exports which() and where()
11
12         my $exe_path = which('perldoc');
13
14         my @paths = where('perl');
15         - Or -
16         my @paths = which('perl'); # an array forces search for all of them
17

DESCRIPTION

19       "File::Which" was created to be able to get the paths to executable
20       programs on systems under which the `which' program wasn't implemented
21       in the shell.
22
23       "File::Which" searches the directories of the user's "PATH" (as
24       returned by "File::Spec->path()"), looking for executable files having
25       the name specified as a parameter to "which()". Under Win32 systems,
26       which do not have a notion of directly executable files, but uses spe‐
27       cial extensions such as ".exe" and ".bat" to identify them,
28       "File::Which" takes extra steps to assure that you will find the cor‐
29       rect file (so for example, you might be searching for "perl", it'll try
30       "perl.exe", "perl.bat", etc.)
31

Steps Used on Win32, DOS, OS2 and VMS

33       Windows NT
34
35       Windows NT has a special environment variable called "PATHEXT", which
36       is used by the shell to look for executable files. Usually, it will
37       contain a list in the form ".EXE;.BAT;.COM;.JS;.VBS" etc. If
38       "File::Which" finds such an environment variable, it parses the list
39       and uses it as the different extensions.
40
41       Windows 9x and other ancient Win/DOS/OS2
42
43       This set of operating systems don't have the "PATHEXT" variable, and
44       usually you will find executable files there with the extensions
45       ".exe", ".bat" and (less likely) ".com". "File::Which" uses this hard‐
46       coded list if it's running under Win32 but does not find a "PATHEXT"
47       variable.
48
49       VMS
50
51       Same case as Windows 9x: uses ".exe" and ".com" (in that order).
52

Functions

54       which($short_exe_name)
55
56       Exported by default.
57
58       $short_exe_name is the name used in the shell to call the program (for
59       example, "perl").
60
61       If it finds an executable with the name you specified, "which()" will
62       return the absolute path leading to this executable (for example,
63       "/usr/bin/perl" or "C:\Perl\Bin\perl.exe").
64
65       If it does not find the executable, it returns "undef".
66
67       If "which()" is called in list context, it will return all the matches.
68
69       where($short_exe_name)
70
71       Not exported by default.
72
73       Same as "which($short_exe_name)" in array context. Same as the `where'
74       utility, will return an array containing all the path names matching
75       $short_exe_name.
76

Bugs and Caveats

78       Not tested on VMS or MacOS, although there is platform specific code
79       for those. Anyone who haves a second would be very kind to send me a
80       report of how it went.
81
82       File::Spec adds the current directory to the front of PATH if on Win32,
83       VMS or MacOS. I have no knowledge of those so don't know if the current
84       directory is searced first or not. Could someone please tell me?
85

Author

87       Per Einar Ellefsen, <per.einar (at) skynet.be>
88
89       Originated in modperl-2.0/lib/Apache/Build.pm. Changed for use in Doc‐
90       Set (for the mod_perl site) and Win32-awareness by me, with slight mod‐
91       ifications by Stas Bekman, then extracted to create "File::Which".
92
93       Version 0.04 had some significant platform-related changes, taken from
94       the Perl Power Tools `which' implementation by Abigail with enhance‐
95       ments from Peter Prymmer. See http://www.perl.com/lan
96       guage/ppt/src/which/index.html for more information.
97

License

99       This library is free software; you can redistribute it and/or modify it
100       under the same terms as Perl itself.
101

See Also

103       File::Spec, which(1), Perl Power Tools: http://www.perl.com/lan
104       guage/ppt/index.html .
105
106
107
108perl v5.8.8                       2002-06-24                          Which(3)
Impressum