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::Which" searches 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 ".exe" and ".bat" to identify them, "File::Which" takes extra steps to assure that you will find the correct file (so for example, you might be searching for "perl", it'll try "perl.exe", "perl.bat", etc.)
$short_exe_name is the name used in the shell to call the program (for example, "perl").
If it finds an executable with the name you specified, "which()" will return the absolute path leading to this executable (for example, "/usr/bin/perl" or "C:\Perl\Bin\perl.exe").
If it does not find the executable, it returns "undef".
If "which()" is called in list context, it will return all the matches.
Same as "which($short_exe_name)" in array context. Same as the `where' utility, will return an array containing all the path names matching $short_exe_name.
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?
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 "File::Which".
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.
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |