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.bat < prev    next >
Encoding:
DOS Batch File  |  2003-04-15  |  2.5 KB  |  118 lines

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