File::SearchPath(3pm)
π File::SearchPath π
okay so bestie, this is the manual page for the Perl module File::SearchPath, part of the User Contributed Perl Documentation. it's a tiny little module with one big job and honestly? it ate. let's get into it π«Ά
πΈ NAME πΈ
File::SearchPath β search for a file in an environment variable path β¨
like, you've got a path-like env var. you want to find a file in it. that's the whole vibe.
π SYNOPSIS π
use File::SearchPath qw/ searchpath /;
$file = searchpath( 'libperl.a', env => 'LD_LIBRARY_PATH' );
$file = searchpath( 'my.cfg', env => 'CFG_DIR', subdir => 'ME' );
$path = searchpath( $file, env => 'PATH', exe => 1 );
$path = searchpath( $file, env => 'PATH', dir => 1 );
$file = searchpath( 'ls', $ENV{PATH} );
$exe = searchpath( 'ls' );
π¦ DESCRIPTION π¦
this module gives you the ability to search a path-like environment variable for a file. and no, that file does not have to be an executable β it can be literally anything you want, it's giving range. π
β¨ FUNCTIONS β¨
the following functions can be exported by this module. (yes, there's one. she's the main character. periodt.)
π searchpath
this is the core function, the moment, the icon. the only mandatory argument is the name of a file to be located. that filename should not be absolute, though it can include directory specifications. iykyk.
$path = searchpath( $file );
@matches = searchpath( $file );
if you only pass two arguments, it just assumes the second one is a path-like string. this interface exists purely for backwards compatibility with File::SearchPath version 0.01. it is not as portable as specifying the name of the environment variable, bestie. also note β when you call the subroutine this way, no specific attempt is made to check whether the file is executable. nope, none. π
$path = searchpath( $file, $ENV{PATH} );
by default, this searches $PATH for executable files and is equivalent to:
$path = searchpath( $file, env => 'PATH', exe => 0 );
hash-like options can be used to alter the behaviour of the search:
envβ name of the environment variable to use as a starting point for the search. should be a path-like environment variable such as$PATH,$LD_LIBRARY_PATHetc. defaults to$PATH. an error occurs if the environment variable is not set or not defined. if it is defined but contains a blank string, the current directory will be assumed. πexeβ if true, only executable files will be located in the search path. if$PATHis being searched, the default is for this to be true. for all other environment variables the default is false. if thediroption is specified,exewill always default to false. the way that works πdirβ if true, only directories will be located in the search path. default is false.dirandexeare not allowed to be true in the same call β that triggers acroak()on error. so like, pick a lane babe.subdirβ if you know your file is in a subdirectory of the path described by the environment variable, you can specify that directory here. alternatively, you can just include the path in the file name itself. your call, both slay. β¨
in scalar context the first match is returned. in list context all matches are returned, in the order corresponding to the directories listed in the environment variable. π
returns undef (or an empty list) if no match could be found. no match, no vibes, it happens. π
if an absolute file name is provided, that filename is returned if it exists and is readable, else undef is returned.
π HISTORY π
File::SearchPath used to exist on CPAN (now on backpan) and was written by Robert Spier. this version is completely new but retains an interface that is compatible with Robert's version. thanks to Robert for allowing me to reuse this module name. legend behaviour fr fr π«Ά
π NOTES π
if the Env::Path module is installed it will be used. this allows for more flexibility than simply assuming colon-separated paths. obsessed with a module that upgrades itself. π
πΈ SEE ALSO πΈ
Env::Path, File::Which, File::Find, File::Find::Run, File::Where.
π AUTHOR π
Tim Jenness <tjenness@cpan.org>
Copyright (C) 2005,2006, 2008 Particle Physics and Astronomy Research Council. Copyright (C) 2009-2010 Science and Technology Facilities Council. Copyright (C) 2015 Tim Jenness All Rights Reserved.
this program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
this program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. see the GNU General Public License for more details. (not me warning you about implied warranties, but like, it's in there. π)
you should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
and that's the whole page bestie, no notes. π
this was perl v5.40.0, dated 2024-11-22, and it lives in the File::SearchPath(3pm) manual. mwah. πβ¨π¦
π¦ where this page comes from
- debian trixie: libfile-searchpath-perl 0.07-1 Β· GPL-2.0-or-later
- ubuntu resolute: libfile-searchpath-perl 0.07-1 Β· GPL-2.0-or-later
- ubuntu stonking: libfile-searchpath-perl 0.07-1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms