Dir::Which - Search for directory entries in a list of directories.


Dir-Which documentation  | view source Contained in the Dir-Which distribution.

Index


NAME

Top

Dir::Which - Search for directory entries in a list of directories.

SYNOPSIS

Top

  use Dir::Which qw/ which /;

  @entries = which(
               -entry => "myprog.conf", 
               -env => "myprog_path", 
               -defaultpath => ".:".$FindBin::Bin.":/etc:/usr/local/etc") ;

DESCRIPTION

Top

This module searches directory entries (files, dirs, links, named pipes...) in a list of directories specified as a path-like string.

The path string can be specified in an environment variable or as an argument.

EXPORT

Top

which

FUNCTION

Top

which

This fonction takes named arguments :

-entry (mandatory)

The name of the searched entry.

-env (optional)

The name of a environment variable supposed to be a path-like string, and which be used to search the specified entry. If one or more entries are found in this path, the search ends and returns these values.

-defaultpath (optional)

The path used to search the specified entry, if -env argument is missing, or if this environment variable doesn't exist, or if no entry have been found in it.

RETURN VALUE

Top

In scalar context, the first match is returned according to the order of the directories listed in the path string, or undef if no match can be found.

In list context, all matches are returned in the order corresponding to the directories listed in the path string (and so an empty list if no match is found).

EXAMPLES

Top

  use Dir::Which qw/ which /;

  $file = which(
               -entry => "myprog.conf", 
               -defaultpath => "/etc:/usr/local/etc"
          ) ;

Searches the absolute name of myprog.conf successivement in the directories /etc and /usr/local/etc. Returns the first entry found.

  use Dir::Which qw/ which /;
  use FindBin qw($Bin) ;

  @entries = which(
               -entry => "myprog.d", 
               -defaultpath => ".:".$FindBin::Bin.":/etc:/usr/local/etc"
             ) ;

Returns the absolute names of myprog.d searched in the current directory, the directory which contains the program binary, /etc and /usr/local/etc.

  use Dir::Which qw/ which /;

  $file = which(
               -entry => "myprog.conf", 
               -env => "myprog_path"
          ) ;

Searches the absolute name of myprog.conf in the path stored in the environment variable myprog_path. Returns the name of the first file found, or undef if no entry found.

  use Dir::Which qw/ which /;
  use FindBin qw($Bin) ;

  $file = which(
               -entry => "myprog.conf", 
               -env => "myprog_path", 
               -defaultpath => ".:".$FindBin::Bin.":/etc:/usr/local/etc"
          ) ;

Searches the absolute name of myprog.conf in the path stored in the environment variable myprog_path. If no file has been found, searches successivement in the current directory, the directory which contains the program binary, /etc and /usr/local/etc. Returns the name of the first entry found, or undef if no entry found.

NOTES

Top

If Env::Path module is installed it will be used. This allows for more portability than simply assuming colon-separated paths.

SEE ALSO

Top

File::SearchPath, FindBin, Env::Path, File::Which.

AUTHOR

Top

Jacquelin Charbonnel, <jacquelin.charbonnel at math.cnrs.fr>

BUGS

Top

Please report any bugs or feature requests to bug-dir-which at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dir-Which. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Dir::Which

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Dir-Which

* CPAN Ratings

http://cpanratings.perl.org/d/Dir-Which

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dir-Which

* Search CPAN

http://search.cpan.org/dist/Dir-Which

ACKNOWLEDGEMENTS

Top

Dir::Which is inspired by File::SearchPath written by Tim Jenness. Thanks to Tim for allowing me to reuse his idea.

COPYRIGHT & LICENSE

Top


Dir-Which documentation  | view source Contained in the Dir-Which distribution.