home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / pwhich < prev    next >
Encoding:
Text File  |  2002-06-24  |  2.1 KB  |  102 lines

  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4.  
  5. use File::Which;
  6. use Getopt::Std;
  7.  
  8. my %opts = ();
  9.  
  10. getopts('av', \%opts);
  11.  
  12. my @files = @ARGV;
  13.  
  14. if ($opts{v}) {
  15.     print <<"END";
  16. This is pwhich running File::Which version $File::Which::VERSION
  17.  
  18. Copyright 2002 Per Einar Ellefsen.
  19. This program is free software; you can redistribute it and/or modify
  20. it under the same terms as Perl itself.
  21. END
  22.  
  23.     exit;
  24. }
  25.  
  26. unless(@files) {
  27.     print <<"EOS";
  28. Usage: $0 [-a] [-v] programname [programname ...]
  29.       -a        Print all matches in PATH, not just the first.
  30.       -v        Prints version and exits
  31.  
  32. EOS
  33.           
  34.     exit;
  35. }
  36.  
  37. for my $file (@files) {
  38.     my @result = $opts{a} ? which($file) : scalar which($file); # need to force scalar
  39.     @result = () unless defined $result[0];   # we might end up with @result = (undef) -> 1 elem
  40.     for my $result (@result) {
  41.         print "$result\n" if $result;
  42.     }
  43.     print STDERR "pwhich: no $file in PATH\n" unless @result;
  44. }
  45.  
  46. __END__
  47.  
  48. =head1 NAME
  49.  
  50. pwhich - Perl-only `which'
  51.  
  52. =head1 Synopsis
  53.  
  54.   $ pwhich perl
  55.   $ pwhich -a perl          # print all matches
  56.   $ pwhich perl perldoc ... # look for multiple programs
  57.   $ pwhich -a perl perldoc ...
  58.  
  59. =head1 DESCRIPTION
  60.  
  61. `pwhich' is a command-line utility program for finding paths to other
  62. programs based on the user's C<PATH>. It is similar to the usualy Unix
  63. tool `which', and tries to emulate its functionality, but is written
  64. purely in Perl (uses the module C<File::Which>), so is portable.
  65.  
  66.  
  67. =head1 Calling syntax
  68.  
  69.   $ pwhich [-a] [-v] programname [programname ...]
  70.  
  71. =head2 Options
  72.  
  73. =over
  74.  
  75. =item -a
  76.  
  77. The option I<-a> will make C<pwhich> print all matches found in the
  78. C<PATH> variable instead of just the first one. Each match is printed
  79. on a separate line.
  80.  
  81. =item -v
  82.  
  83. Prints version (of C<File::Which>) and copyright notice and exits.
  84.  
  85. =back
  86.  
  87. =head1 License
  88.  
  89. This program is free software; you can redistribute it and/or modify
  90. it under the same terms as Perl itself.
  91.  
  92. =head1 See Also
  93.  
  94. L<perl>, L<File::Which>, L<which(1)>
  95.  
  96. =head1 Author
  97.  
  98. Per Einar Ellefsen, E<lt>per.einar (at) skynet.beE<gt>
  99.  
  100. =cut
  101.  
  102.