{
    "mode": "perldoc",
    "parameter": "File::Which",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/File%3A%3AWhich/json",
    "generated": "2026-06-12T13:52:56Z",
    "synopsis": "use File::Which;                  # exports which()\nuse File::Which qw(which where);  # exports which() and where()\nmy $exepath = which 'perldoc';\nmy @paths = where 'perl';\n# Or\nmy @paths = which 'perl'; # an array forces search for all of them",
    "sections": {
        "NAME": {
            "content": "File::Which - Perl implementation of the which utility as an API\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 1.23\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use File::Which;                  # exports which()\nuse File::Which qw(which where);  # exports which() and where()\n\nmy $exepath = which 'perldoc';\n\nmy @paths = where 'perl';\n# Or\nmy @paths = which 'perl'; # an array forces search for all of them\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "File::Which finds the full or relative paths to executable programs on the system. This is\nnormally the function of \"which\" utility. \"which\" is typically implemented as either a program\nor a built in shell command. On some platforms, such as Microsoft Windows it is not provided as\npart of the core operating system. This module provides a consistent API to this functionality\nregardless of the underlying platform.\n\nThe focus of this module is correctness and portability. As a consequence platforms where the\ncurrent directory is implicitly part of the search path such as Microsoft Windows will find\nexecutables in the current directory, whereas on platforms such as UNIX where this is not the\ncase executables in the current directory will only be found if the current directory is\nexplicitly added to the path.\n\nIf you need a portable \"which\" on the command line in an environment that does not provide it,\ninstall App::pwhich which provides a command line interface to this API.\n",
            "subsections": [
                {
                    "name": "Implementations",
                    "content": "File::Which searches the directories of the user's \"PATH\" (the current implementation uses\nFile::Spec#path to determine the correct \"PATH\"), looking for executable files having the name\nspecified as a parameter to \"which\". Under Win32 systems, which do not have a notion of directly\nexecutable files, but uses special extensions such as \".exe\" and \".bat\" to identify them,\n\"File::Which\" takes extra steps to assure that you will find the correct file (so for example,\nyou might be searching for \"perl\", it'll try perl.exe, perl.bat, etc.)\n\nLinux, *BSD and other UNIXes\nThere should not be any surprises here. The current directory will not be searched unless it is\nexplicitly added to the path.\n\nModern Windows (including NT, XP, Vista, 7, 8, 10 etc)\nWindows NT has a special environment variable called \"PATHEXT\", which is used by the shell to\nlook for executable files. Usually, it will contain a list in the form \".EXE;.BAT;.COM;.JS;.VBS\"\netc. If \"File::Which\" finds such an environment variable, it parses the list and uses it as the\ndifferent extensions.\n\nCygwin\nCygwin provides a Unix-like environment for Microsoft Windows users. In most ways it works like\nother Unix and Unix-like environments, but in a few key aspects it works like Windows. As with\nother Unix environments, the current directory is not included in the search unless it is\nexplicitly included in the search path. Like on Windows, files with \".EXE\" or <.BAT> extensions\nwill be discovered even if they are not part of the query. \".COM\" or extensions specified using\nthe \"PATHEXT\" environment variable will NOT be discovered without the fully qualified name,\nhowever.\n\nWindows ME, 98, 95, MS-DOS, OS/2\nThis set of operating systems don't have the \"PATHEXT\" variable, and usually you will find\nexecutable files there with the extensions \".exe\", \".bat\" and (less likely) \".com\".\n\"File::Which\" uses this hardcoded list if it's running under Win32 but does not find a \"PATHEXT\"\nvariable.\n\nAs of 2015 none of these platforms are tested frequently (or perhaps ever), but the current\nmaintainer is determined not to intentionally remove support for older operating systems.\n\nVMS\nSame case as Windows 9x: uses \".exe\" and \".com\" (in that order).\n\nAs of 2015 the current maintainer does not test on VMS, and is in fact not certain it has ever\nbeen tested on VMS. If this platform is important to you and you can help me verify and or\nsupport it on that platform please contact me.\n"
                }
            ]
        },
        "FUNCTIONS": {
            "content": "which\nmy $path = which $shortexename;\nmy @paths = which $shortexename;\n\nExported by default.\n\n$shortexename is the name used in the shell to call the program (for example, \"perl\").\n\nIf it finds an executable with the name you specified, \"which()\" will return the absolute path\nleading to this executable (for example, /usr/bin/perl or C:\\Perl\\Bin\\perl.exe).\n\nIf it does *not* find the executable, it returns \"undef\".\n\nIf \"which()\" is called in list context, it will return *all* the matches.\n\nwhere\nmy @paths = where $shortexename;\n\nNot exported by default.\n\nSame as \"which\" in array context. Similar to the \"where\" csh built-in command or \"which -a\"\ncommand for platforms that support the \"-a\" option. Will return an array containing all the path\nnames matching $shortexename.\n",
            "subsections": []
        },
        "GLOBALS": {
            "content": "$IMPLICITCURRENTDIR\nTrue if the current directory is included in the search implicitly on whatever platform you are\nusing. Normally the default is reasonable, but on Windows the current directory is included\nimplicitly for older shells like \"cmd.exe\" and \"command.com\", but not for newer shells like\nPowerShell. If you overrule this default, you should ALWAYS localize the variable to the\ntightest scope possible, since setting this variable from a module can affect other modules.\nThus on Windows you can get the correct result if the user is running either \"cmd.exe\" or\nPowerShell on Windows you can do this:\n\nuse File::Which qw( which );\nuse Shell::Guess;\n\nmy $path = do {\nmy $ispower = Shell::Guess->runningshell->ispower;\nlocal $File::Which::IMPLICITCURRENTDIR = !$ispower;\nwhich 'foo';\n};\n\nFor a variety of reasons it is difficult to accurately compute the shell that a user is using,\nbut Shell::Guess makes a reasonable effort.\n",
            "subsections": []
        },
        "CAVEATS": {
            "content": "This module has no non-core requirements for Perl 5.6.2 and better.\n\nThis module is fully supported back to Perl 5.8.1. It may work on 5.8.0. It should work on Perl\n5.6.x and I may even test on 5.6.2. I will accept patches to maintain compatibility for such\nolder Perls, but you may need to fix it on 5.6.x / 5.8.0 and send me a patch.\n\nNot tested on VMS although there is platform specific code for those. Anyone who haves a second\nwould be very kind to send me a report of how it went.\n",
            "subsections": []
        },
        "SUPPORT": {
            "content": "Bugs should be reported via the GitHub issue tracker\n\n<https://github.com/plicease/File-Which/issues>\n\nFor other issues, contact the maintainer.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "pwhich, App::pwhich\nCommand line interface to this module.\n\nIPC::Cmd\nThis module provides (among other things) a \"canrun\" function, which is similar to \"which\".\nIt is a much heavier module since it does a lot more, and if you use \"canrun\" it pulls in\nExtUtils::MakeMaker. This combination may be overkill for applications which do not need\nIPC::Cmd's complicated interface for running programs, or do not need the memory overhead\nrequired for installing Perl modules.\n\nAt least some older versions will find executables in the current directory, even if the\ncurrent directory is not in the search path (which is the default on modern Unix).\n\n\"canrun\" converts directory path name to the 8.3 version on Windows using\n\"Win32::GetShortPathName\" in some cases. This is frequently useful for tools that just need\nto run something using \"system\" in scalar mode, but may be inconvenient for tools like\nApp::pwhich where user readability is a premium. Relying on \"Win32::GetShortPathName\" to\nproduce filenames without spaces is problematic, as 8.3 filenames can be turned off with\ntweaks to the registry (see <https://technet.microsoft.com/en-us/library/cc959352.aspx>).\n\nDevel::CheckBin\nThis module purports to \"check that a command is available\", but does not provide any\ndocumentation on how you might use it.\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "*   Per Einar Ellefsen <pereinar@cpan.org>\n\n*   Adam Kennedy <adamk@cpan.org>\n\n*   Graham Ollis <plicease@cpan.org>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "This software is copyright (c) 2002 by Per Einar Ellefsen <pereinar@cpan.org>.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl\n5 programming language system itself.\n",
            "subsections": []
        }
    },
    "summary": "File::Which - Perl implementation of the which utility as an API",
    "flags": [],
    "examples": [],
    "see_also": []
}