perldoc cleanups (variant of changes suggested by Christian Lemburg
[p5sagit/p5-mst-13.2.git] / utils / perldoc.PL
CommitLineData
4633a7c4 1#!/usr/local/bin/perl
2
3use Config;
4use File::Basename qw(&basename &dirname);
8a5546a1 5use Cwd;
4633a7c4 6
85880f03 7# List explicitly here the variables you want Configure to
8# generate. Metaconfig only looks for shell variables, so you
9# have to mention them as if they were shell variables, not
10# %Config entries. Thus you write
4633a7c4 11# $startperl
85880f03 12# to ensure Configure will look for $Config{startperl}.
4633a7c4 13
14# This forces PL files to create target in same directory as PL file.
15# This is so that make depend always knows where to find PL derivatives.
8a5546a1 16$origdir = cwd;
44a8e56a 17chdir dirname($0);
18$file = basename($0, '.PL');
774d564b 19$file .= '.com' if $^O eq 'VMS';
4633a7c4 20
21open OUT,">$file" or die "Can't create $file: $!";
22
23print "Extracting $file (with variable substitutions)\n";
24
25# In this section, perl variables will be expanded during extraction.
26# You can use $Config{...} to use Configure variables.
27
85880f03 28print OUT <<"!GROK!THIS!";
5f05dabc 29$Config{startperl}
30 eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
c5ae3962 31 if 0;
55497cff 32
c5ae3962 33use strict;
34my \@pagers = ();
55497cff 35push \@pagers, "$Config{'pager'}" if -x "$Config{'pager'}";
4633a7c4 36!GROK!THIS!
37
38# In the following, perl variables are not expanded during extraction.
39
40print OUT <<'!NO!SUBS!';
41
42#
43# Perldoc revision #1 -- look up a piece of documentation in .pod format that
44# is embedded in the perl installation tree.
45#
46# This is not to be confused with Tom Christianson's perlman, which is a
47# man replacement, written in perl. This perldoc is strictly for reading
48# the perl manuals, though it too is written in perl.
4633a7c4 49
febd60db 50if (@ARGV<1) {
c5ae3962 51 my $me = $0; # Editing $0 is unportable
fb73857a 52 $me =~ s,.*/,,;
4633a7c4 53 die <<EOF;
5315ba28 54Usage: $me [-h] [-r] [-i] [-v] [-t] [-u] [-m] [-l] [-F] [-X] PageName|ModuleName|ProgramName
0b166b66 55 $me -f PerlFunc
a3cb178b 56 $me -q FAQKeywords
4633a7c4 57
89b8affa 58The -h option prints more help. Also try "perldoc perldoc" to get
59aquainted with the system.
4633a7c4 60EOF
61}
62
63use Getopt::Std;
59586d77 64use Config '%Config';
65
c5ae3962 66my @global_found = ();
67my $global_target = "";
fb73857a 68
c5ae3962 69my $Is_VMS = $^O eq 'VMS';
70my $Is_MSWin32 = $^O eq 'MSWin32';
71my $Is_Dos = $^O eq 'dos';
4633a7c4 72
73sub usage{
ff0cee69 74 warn "@_\n" if @_;
75 # Erase evidence of previous errors (if any), so exit status is simple.
76 $! = 0;
4633a7c4 77 die <<EOF;
31bdbec1 78perldoc [options] PageName|ModuleName|ProgramName...
79perldoc [options] -f BuiltinFunction
a3cb178b 80perldoc [options] -q FAQRegex
31bdbec1 81
82Options:
137443ea 83 -h Display this help message
5315ba28 84 -r Recursive search (slow)
febd60db 85 -i Ignore case
137443ea 86 -t Display pod using pod2text instead of pod2man and nroff
87 (-t is the default on win32)
85880f03 88 -u Display unformatted pod text
a3cb178b 89 -m Display module's file in its entirety
90 -l Display the module's file name
cce34969 91 -F Arguments are file names, not modules
137443ea 92 -v Verbosely describe what's going on
89b8affa 93 -X use index if present (looks for pod.idx at $Config{archlib})
54ac30b1 94 -q Search the text of questions (not answers) in perlfaq[1-9]
a3cb178b 95
4633a7c4 96PageName|ModuleName...
febd60db 97 is the name of a piece of documentation that you want to look at. You
4633a7c4 98 may either give a descriptive name of the page (as in the case of
febd60db 99 `perlfunc') the name of a module, either like `Term::Info',
100 `Term/Info', the partial name of a module, like `info', or
4633a7c4 101 `makemaker', or the name of a program, like `perldoc'.
31bdbec1 102
103BuiltinFunction
104 is the name of a perl function. Will extract documentation from
105 `perlfunc'.
a3cb178b 106
107FAQRegex
108 is a regex. Will search perlfaq[1-9] for and extract any
109 questions that match.
110
febd60db 111Any switches in the PERLDOC environment variable will be used before the
89b8affa 112command line arguments. The optional pod index file contains a list of
113filenames, one per line.
4633a7c4 114
115EOF
116}
117
febd60db 118if (defined $ENV{"PERLDOC"}) {
c5ae3962 119 require Text::ParseWords;
120 unshift(@ARGV, Text::ParseWords::shellwords($ENV{"PERLDOC"}));
121}
122!NO!SUBS!
123
124my $getopts = "mhtluvriFf:Xq:";
125print OUT <<"!GET!OPTS!";
4633a7c4 126
c5ae3962 127use vars qw( @{[map "\$opt_$_", ($getopts =~ /\w/g)]} );
4633a7c4 128
c5ae3962 129getopts("$getopts") || usage;
130!GET!OPTS!
4633a7c4 131
c5ae3962 132print OUT <<'!NO!SUBS!';
85880f03 133
c5ae3962 134usage if $opt_h;
4633a7c4 135
c5ae3962 136my $podidx;
febd60db 137if ($opt_X) {
0d3da1c8 138 $podidx = "$Config{'archlib'}/pod.idx";
139 $podidx = "" unless -f $podidx && -r _ && -M _ <= 7;
140}
89b8affa 141
febd60db 142if ((my $opts = do{ local $^W; $opt_t + $opt_u + $opt_m + $opt_l }) > 1) {
137443ea 143 usage("only one of -t, -u, -m or -l")
febd60db 144}
145elsif ($Is_MSWin32 || $Is_Dos) {
c5ae3962 146 $opt_t = 1 unless $opts
137443ea 147}
4633a7c4 148
7eda7aea 149if ($opt_t) { require Pod::Text; import Pod::Text; }
4633a7c4 150
c5ae3962 151my @pages;
31bdbec1 152if ($opt_f) {
febd60db 153 @pages = ("perlfunc");
154}
155elsif ($opt_q) {
156 @pages = ("perlfaq1" .. "perlfaq9");
157}
158else {
159 @pages = @ARGV;
31bdbec1 160}
161
fb73857a 162# Does this look like a module or extension directory?
163if (-f "Makefile.PL") {
164 # Add ., lib and blib/* libs to @INC (if they exist)
165 unshift(@INC, '.');
166 unshift(@INC, 'lib') if -d 'lib';
167 require ExtUtils::testlib;
168}
169
4633a7c4 170sub containspod {
fb73857a 171 my($file, $readit) = @_;
172 return 1 if !$readit && $file =~ /\.pod$/i;
173 local($_);
174 open(TEST,"<$file");
febd60db 175 while (<TEST>) {
176 if (/^=head/) {
fb73857a 177 close(TEST);
178 return 1;
4633a7c4 179 }
fb73857a 180 }
181 close(TEST);
182 return 0;
4633a7c4 183}
184
84902520 185sub minus_f_nocase {
5315ba28 186 my($dir,$file) = @_;
187 my $path = join('/',$dir,$file);
188 return $path if -f $path and -r _;
189 if (!$opt_i or $Is_VMS or $Is_MSWin32 or $Is_Dos or $^O eq 'os2') {
febd60db 190 # on a case-forgiving file system or if case is important
5315ba28 191 # that is it all we can do
0cf744f2 192 warn "Ignored $path: unreadable\n" if -f _;
fb73857a 193 return '';
84902520 194 }
4633a7c4 195 local *DIR;
196 local($")="/";
5315ba28 197 my @p = ($dir);
198 my($p,$cip);
4633a7c4 199 foreach $p (split(/\//, $file)){
fb73857a 200 my $try = "@p/$p";
201 stat $try;
febd60db 202 if (-d _) {
4633a7c4 203 push @p, $p;
fb73857a 204 if ( $p eq $global_target) {
c5ae3962 205 my $tmp_path = join ('/', @p);
fb73857a 206 my $path_f = 0;
207 for (@global_found) {
208 $path_f = 1 if $_ eq $tmp_path;
209 }
210 push (@global_found, $tmp_path) unless $path_f;
211 print STDERR "Found as @p but directory\n" if $opt_v;
212 }
febd60db 213 }
214 elsif (-f _ && -r _) {
fb73857a 215 return $try;
febd60db 216 }
217 elsif (-f _) {
fb73857a 218 warn "Ignored $try: unreadable\n";
febd60db 219 }
220 else {
4633a7c4 221 my $found=0;
222 my $lcp = lc $p;
223 opendir DIR, "@p";
224 while ($cip=readdir(DIR)) {
225 if (lc $cip eq $lcp){
226 $found++;
227 last;
228 }
229 }
230 closedir DIR;
231 return "" unless $found;
232 push @p, $cip;
fb73857a 233 return "@p" if -f "@p" and -r _;
0cf744f2 234 warn "Ignored @p: unreadable\n" if -f _;
4633a7c4 235 }
236 }
5315ba28 237 return "";
fb73857a 238}
eb459f90 239
fb73857a 240
241sub check_file {
5315ba28 242 my($dir,$file) = @_;
3046dd9f 243 if ($opt_m) {
5315ba28 244 return minus_f_nocase($dir,$file);
febd60db 245 }
246 else {
5315ba28 247 my $path = minus_f_nocase($dir,$file);
249edfdf 248 return $path if length $path and containspod($path);
3046dd9f 249 }
5315ba28 250 return "";
fb73857a 251}
252
253
254sub searchfor {
255 my($recurse,$s,@dirs) = @_;
256 $s =~ s!::!/!g;
257 $s = VMS::Filespec::unixify($s) if $Is_VMS;
258 return $s if -f $s && containspod($s);
259 printf STDERR "Looking for $s in @dirs\n" if $opt_v;
260 my $ret;
261 my $i;
262 my $dir;
263 $global_target = (split('/', $s))[-1];
264 for ($i=0; $i<@dirs; $i++) {
265 $dir = $dirs[$i];
266 ($dir = VMS::Filespec::unixpath($dir)) =~ s!/$!! if $Is_VMS;
5315ba28 267 if ( ( $ret = check_file $dir,"$s.pod")
268 or ( $ret = check_file $dir,"$s.pm")
269 or ( $ret = check_file $dir,$s)
fb73857a 270 or ( $Is_VMS and
5315ba28 271 $ret = check_file $dir,"$s.com")
febd60db 272 or ( $^O eq 'os2' and
5315ba28 273 $ret = check_file $dir,"$s.cmd")
0151c6ef 274 or ( ($Is_MSWin32 or $Is_Dos or $^O eq 'os2') and
5315ba28 275 $ret = check_file $dir,"$s.bat")
276 or ( $ret = check_file "$dir/pod","$s.pod")
277 or ( $ret = check_file "$dir/pod",$s)
fb73857a 278 ) {
279 return $ret;
280 }
eb459f90 281
fb73857a 282 if ($recurse) {
283 opendir(D,$dir);
284 my @newdirs = map "$dir/$_", grep {
285 not /^\.\.?$/ and
286 not /^auto$/ and # save time! don't search auto dirs
287 -d "$dir/$_"
288 } readdir D;
289 closedir(D);
290 next unless @newdirs;
291 @newdirs = map((s/.dir$//,$_)[1],@newdirs) if $Is_VMS;
292 print STDERR "Also looking in @newdirs\n" if $opt_v;
293 push(@dirs,@newdirs);
294 }
295 }
296 return ();
297}
4633a7c4 298
eb459f90 299sub filter_nroff {
300 my @data = split /\n{2,}/, shift;
301 shift @data while @data and $data[0] !~ /\S/; # Go to header
302 shift @data if @data and $data[0] =~ /Contributed\s+Perl/; # Skip header
303 pop @data if @data and $data[-1] =~ /^\w/; # Skip footer, like
304 # 28/Jan/99 perl 5.005, patch 53 1
305 join "\n\n", @data;
306}
307
febd60db 308sub printout {
309 my ($file, $tmp, $filter) = @_;
310 my $err;
311
312 if ($opt_t) {
313 open(TMP,">>$tmp")
314 or warn("Can't open $tmp: $!"), return;
315 Pod::Text::pod2text($file,*TMP);
316 close TMP;
317 }
318 elsif (not $opt_u) {
319 my $cmd = "pod2man --lax $file | nroff -man";
320 $cmd .= " | col -x" if $^O =~ /hpux/;
321 my $rslt = `$cmd`;
322 $rslt = filter_nroff($rslt) if $filter;
323 unless (($err = $?)) {
324 open(TMP,">>$tmp") or warn("Can't open $tmp: $!"), return;
325 print TMP $rslt;
326 close TMP;
327 }
328 }
329 if ($opt_u or $err or -z $tmp) {
330 open(OUT,">>$tmp") or warn("Can't open $tmp: $!"), return;
331 open(IN,"<$file") or warn("Can't open $file: $!"), return;
332 my $cut = 1;
333 while (<IN>) {
334 $cut = $1 eq 'cut' if /^=(\w+)/;
335 next if $cut;
336 print OUT;
337 }
338 close IN;
339 close OUT;
340 }
341}
342
343sub page {
344 my ($tmp, $no_tty, @pagers) = @_;
345 if ($no_tty) {
346 open(TMP,"<$tmp") or warn("Can't open $tmp: $!"), return;
347 print while <TMP>;
348 close TMP;
349 }
350 else {
351 foreach my $pager (@pagers) {
352 system("$pager $tmp") or last;
353 }
354 }
355}
356
357sub cleanup {
358 my @files = @_;
359 for (@files) {
360 1 while unlink($_); #Possibly pointless VMSism
361 }
362}
363
364sub safe_exit {
365 my ($val, @files) = @_;
366 cleanup(@files);
367 exit $val;
368}
369
370sub safe_die {
371 my ($msg, @files) = @_;
372 cleanup(@files);
373 die $msg;
374}
375
c5ae3962 376my @found;
4633a7c4 377foreach (@pages) {
febd60db 378 if ($podidx && open(PODIDX, $podidx)) {
379 my $searchfor = $_;
380 local($_);
381 $searchfor =~ s,::,/,g;
382 print STDERR "Searching for '$searchfor' in $podidx\n" if $opt_v;
383 while (<PODIDX>) {
384 chomp;
385 push(@found, $_) if m,/$searchfor(?:\.(?:pod|pm))?$,i;
cce34969 386 }
febd60db 387 close(PODIDX);
388 next;
389 }
390 print STDERR "Searching for $_\n" if $opt_v;
391 # We must look both in @INC for library modules and in PATH
392 # for executables, like h2xs or perldoc itself.
393 my @searchdirs = @INC;
394 if ($opt_F) {
395 next unless -r;
396 push @found, $_ if $opt_m or containspod($_);
397 next;
398 }
399 unless ($opt_m) {
400 if ($Is_VMS) {
401 my($i,$trn);
402 for ($i = 0; $trn = $ENV{'DCL$PATH;'.$i}; $i++) {
403 push(@searchdirs,$trn);
7eda7aea 404 }
febd60db 405 push(@searchdirs,'perl_root:[lib.pod]') # installed pods
406 }
407 else {
408 push(@searchdirs, grep(-d, split($Config{path_sep},
409 $ENV{'PATH'})));
85880f03 410 }
febd60db 411 }
412 my @files = searchfor(0,$_,@searchdirs);
413 if (@files) {
414 print STDERR "Found as @files\n" if $opt_v;
415 }
416 else {
417 # no match, try recursive search
418 @searchdirs = grep(!/^\.$/,@INC);
419 @files= searchfor(1,$_,@searchdirs) if $opt_r;
420 if (@files) {
421 print STDERR "Loosely found as @files\n" if $opt_v;
422 }
423 else {
424 print STDERR "No documentation found for \"$_\".\n";
425 if (@global_found) {
426 print STDERR "However, try\n";
427 for my $dir (@global_found) {
428 opendir(DIR, $dir) or die "$!";
429 while (my $file = readdir(DIR)) {
430 next if ($file =~ /^\./);
431 $file =~ s/\.(pm|pod)$//;
432 print STDERR "\tperldoc $_\::$file\n";
433 }
434 closedir DIR;
4633a7c4 435 }
febd60db 436 }
4633a7c4 437 }
febd60db 438 }
439 push(@found,@files);
4633a7c4 440}
441
febd60db 442if (!@found) {
443 exit ($Is_VMS ? 98962 : 1);
4633a7c4 444}
445
44a8e56a 446if ($opt_l) {
447 print join("\n", @found), "\n";
448 exit;
449}
450
877622ba 451my $lines = $ENV{LINES} || 24;
452
c5ae3962 453my $no_tty;
febd60db 454if (! -t STDOUT) { $no_tty = 1 }
455
456# until here we could simply exit or die
457# now we create temporary files that we have to clean up
458# namely $tmp, $buffer
4633a7c4 459
c5ae3962 460my $tmp;
febd60db 461my $buffer;
137443ea 462if ($Is_MSWin32) {
febd60db 463 $tmp = "$ENV{TEMP}\\perldoc1.$$";
464 $buffer = "$ENV{TEMP}\\perldoc1.b$$";
465 push @pagers, qw( more< less notepad );
466 unshift @pagers, $ENV{PAGER} if $ENV{PAGER};
467 for (@found) { s,/,\\,g }
468}
469elsif ($Is_VMS) {
470 $tmp = 'Sys$Scratch:perldoc.tmp1_'.$$;
471 $buffer = 'Sys$Scratch:perldoc.tmp1_b'.$$;
472 push @pagers, qw( most more less type/page );
473}
474elsif ($Is_Dos) {
475 $tmp = "$ENV{TEMP}/perldoc1.$$";
476 $buffer = "$ENV{TEMP}/perldoc1.b$$";
477 $tmp =~ tr!\\/!//!s;
478 $buffer =~ tr!\\/!//!s;
479 push @pagers, qw( less.exe more.com< );
480 unshift @pagers, $ENV{PAGER} if $ENV{PAGER};
481}
482else {
483 if ($^O eq 'os2') {
484 require POSIX;
485 $tmp = POSIX::tmpnam();
486 $buffer = POSIX::tmpnam();
487 unshift @pagers, 'less', 'cmd /c more <';
488 }
489 else {
490 $tmp = "/tmp/perldoc1.$$";
491 $buffer = "/tmp/perldoc1.b$$";
492 }
493 push @pagers, qw( more less pg view cat );
494 unshift @pagers, $ENV{PAGER} if $ENV{PAGER};
4633a7c4 495}
44a8e56a 496unshift @pagers, $ENV{PERLDOC_PAGER} if $ENV{PERLDOC_PAGER};
4633a7c4 497
febd60db 498# all exit calls from here on have to be safe_exit calls (see above)
499# and all die calls safe_die calls to guarantee removal of files and
500# dir as needed
501
7eda7aea 502if ($opt_m) {
febd60db 503 foreach my $pager (@pagers) {
504 system("$pager @found") or safe_exit(0, $tmp, $buffer);
505 }
506 if ($Is_VMS) { eval 'use vmsish qw(status exit); exit $?' }
507 # I don't get the line above. Please patch yourself as needed.
508 safe_exit(1, $tmp, $buffer);
eb459f90 509}
7eda7aea 510
eb459f90 511my @pod;
31bdbec1 512if ($opt_f) {
febd60db 513 my $perlfunc = shift @found;
514 open(PFUNC, $perlfunc)
515 or safe_die("Can't open $perlfunc: $!", $tmp, $buffer);
31bdbec1 516
febd60db 517 # Functions like -r, -e, etc. are listed under `-X'.
518 my $search_string = ($opt_f =~ /^-[rwxoRWXOeszfdlpSbctugkTBMAC]$/)
519 ? 'I<-X' : $opt_f ;
a3cb178b 520
febd60db 521 # Skip introduction
522 while (<PFUNC>) {
523 last if /^=head2 Alphabetical Listing of Perl Functions/;
524 }
7eda7aea 525
febd60db 526 # Look for our function
527 my $found = 0;
528 my $inlist = 0;
529 while (<PFUNC>) {
530 if (/^=item\s+\Q$search_string\E\b/o) {
531 $found = 1;
85880f03 532 }
febd60db 533 elsif (/^=item/) {
534 last if $found > 1 and not $inlist;
535 }
536 next unless $found;
537 if (/^=over/) {
538 ++$inlist;
539 }
540 elsif (/^=back/) {
541 --$inlist;
4633a7c4 542 }
febd60db 543 push @pod, $_;
544 ++$found if /^\w/; # found descriptive text
545 }
546 if (!@pod) {
547 die "No documentation for perl function `$opt_f' found\n";
548 }
4633a7c4 549}
550
febd60db 551if ($opt_q) {
552 local @ARGV = @found; # I'm lazy, sue me.
553 my $found = 0;
554 my %found_in;
555
556 while (<>) {
557 if (/^=head2\s+.*(?:$opt_q)/oi) {
558 $found = 1;
559 push @pod, "=head1 Found in $ARGV\n\n" unless $found_in{$ARGV}++;
4633a7c4 560 }
febd60db 561 elsif (/^=head2/) {
562 $found = 0;
563 }
564 next unless $found;
565 push @pod, $_;
566 }
567 if (!@pod) {
568 safe_die("No documentation for perl FAQ keyword `$opt_q' found\n",
569 $tmp, $buffer);
570 }
571}
572
573my $filter;
574
575if (@pod) {
576 open(TMP,">$buffer") or safe_die("Can't open '$buffer': $!", $tmp, $buffer);
577 print TMP "=over 8\n\n";
578 print TMP @pod;
579 print TMP "=back\n";
580 close TMP;
581 @found = $buffer;
582 $filter = 1;
4633a7c4 583}
584
febd60db 585foreach (@found) {
586 printout($_, $tmp, $filter);
eb459f90 587}
febd60db 588page($tmp, $no_tty, @pagers);
4633a7c4 589
febd60db 590safe_exit(0, $tmp, $buffer);
7eda7aea 591
592__END__
593
594=head1 NAME
595
596perldoc - Look up Perl documentation in pod format.
597
598=head1 SYNOPSIS
599
89b8affa 600B<perldoc> [B<-h>] [B<-v>] [B<-t>] [B<-u>] [B<-m>] [B<-l>] [B<-F>] [B<-X>] PageName|ModuleName|ProgramName
7eda7aea 601
31bdbec1 602B<perldoc> B<-f> BuiltinFunction
603
c8950503 604B<perldoc> B<-q> FAQ Keyword
605
7eda7aea 606=head1 DESCRIPTION
607
40fc7247 608I<perldoc> looks up a piece of documentation in .pod format that is embedded
609in the perl installation tree or in a perl script, and displays it via
610C<pod2man | nroff -man | $PAGER>. (In addition, if running under HP-UX,
611C<col -x> will be used.) This is primarily used for the documentation for
612the perl library modules.
7eda7aea 613
614Your system may also have man pages installed for those modules, in
615which case you can probably just use the man(1) command.
616
617=head1 OPTIONS
618
619=over 5
620
621=item B<-h> help
622
623Prints out a brief help message.
624
625=item B<-v> verbose
626
627Describes search for the item in detail.
628
629=item B<-t> text output
630
631Display docs using plain text converter, instead of nroff. This may be faster,
632but it won't look as nice.
633
634=item B<-u> unformatted
635
636Find docs only; skip reformatting by pod2*
637
638=item B<-m> module
639
640Display the entire module: both code and unformatted pod documentation.
641This may be useful if the docs don't explain a function in the detail
642you need, and you'd like to inspect the code directly; perldoc will find
643the file for you and simply hand it off for display.
644
44a8e56a 645=item B<-l> file name only
646
647Display the file name of the module found.
648
cce34969 649=item B<-F> file names
650
89b8affa 651Consider arguments as file names, no search in directories will be performed.
cce34969 652
31bdbec1 653=item B<-f> perlfunc
654
655The B<-f> option followed by the name of a perl built in function will
656extract the documentation of this function from L<perlfunc>.
657
c8950503 658=item B<-q> perlfaq
659
660The B<-q> option takes a regular expression as an argument. It will search
661the question headings in perlfaq[1-9] and print the entries matching
662the regular expression.
663
89b8affa 664=item B<-X> use an index if present
665
666The B<-X> option looks for a entry whose basename matches the name given on the
667command line in the file C<$Config{archlib}/pod.idx>. The pod.idx file should
668contain fully qualified filenames, one per line.
669
7eda7aea 670=item B<PageName|ModuleName|ProgramName>
671
672The item you want to look up. Nested modules (such as C<File::Basename>)
673are specified either as C<File::Basename> or C<File/Basename>. You may also
1b420867 674give a descriptive name of a page, such as C<perlfunc>. You may also give a
7eda7aea 675partial or wrong-case name, such as "basename" for "File::Basename", but
676this will be slower, if there is more then one page with the same partial
677name, you will only get the first one.
678
679=back
680
681=head1 ENVIRONMENT
682
febd60db 683Any switches in the C<PERLDOC> environment variable will be used before the
7eda7aea 684command line arguments. C<perldoc> also searches directories
685specified by the C<PERL5LIB> (or C<PERLLIB> if C<PERL5LIB> is not
686defined) and C<PATH> environment variables.
687(The latter is so that embedded pods for executables, such as
a3cb178b 688C<perldoc> itself, are available.) C<perldoc> will use, in order of
689preference, the pager defined in C<PERLDOC_PAGER>, C<MANPAGER>, or
690C<PAGER> before trying to find a pager on its own. (C<MANPAGER> is not
691used if C<perldoc> was told to display plain text or unformatted pod.)
7eda7aea 692
eb459f90 693One useful value for C<PERLDOC_PAGER> is C<less -+C -E>.
694
febd60db 695=head1 VERSION
696
697This is perldoc v2.0.
698
7eda7aea 699=head1 AUTHOR
700
701Kenneth Albanowski <kjahds@kjahds.com>
702
febd60db 703Minor updates by Andy Dougherty <doughera@lafcol.lafayette.edu>,
704and others.
7eda7aea 705
7eda7aea 706=cut
707
708#
c5ae3962 709# Version 1.14: Wed Jul 15 01:50:20 EST 1998
710# Robin Barker <rmb1@cise.npl.co.uk>
711# -strict, -w cleanups
89b8affa 712# Version 1.13: Fri Feb 27 16:20:50 EST 1997
713# Gurusamy Sarathy <gsar@umich.edu>
714# -doc tweaks for -F and -X options
137443ea 715# Version 1.12: Sat Apr 12 22:41:09 EST 1997
716# Gurusamy Sarathy <gsar@umich.edu>
717# -various fixes for win32
7eda7aea 718# Version 1.11: Tue Dec 26 09:54:33 EST 1995
719# Kenneth Albanowski <kjahds@kjahds.com>
720# -added Charles Bailey's further VMS patches, and -u switch
721# -added -t switch, with pod2text support
febd60db 722#
7eda7aea 723# Version 1.10: Thu Nov 9 07:23:47 EST 1995
724# Kenneth Albanowski <kjahds@kjahds.com>
725# -added VMS support
726# -added better error recognition (on no found pages, just exit. On
727# missing nroff/pod2man, just display raw pod.)
728# -added recursive/case-insensitive matching (thanks, Andreas). This
729# slows things down a bit, unfortunately. Give a precise name, and
730# it'll run faster.
731#
732# Version 1.01: Tue May 30 14:47:34 EDT 1995
733# Andy Dougherty <doughera@lafcol.lafayette.edu>
734# -added pod documentation.
735# -added PATH searching.
736# -added searching pod/ subdirectory (mainly to pick up perlfunc.pod
737# and friends.
738#
739#
740# TODO:
741#
742# Cache directories read during sloppy match
4633a7c4 743!NO!SUBS!
744
745close OUT or die "Can't close $file: $!";
746chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
747exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
8a5546a1 748chdir $origdir;