perl的pod2usage(-verbose => 2)显示源代码而不是格式化文档

Mat*_*Moy 4 perl perldoc

根据Pod :: Usage文档,pod2usage(-verbose => 2)"整个手册页被打印".但是,在某些情况下,将显示脚本的perl源代码,而不是正确格式化的联机帮助页.

这是一个例子:

use Pod::Usage qw(pod2usage);
pod2usage(-verbose => 2);

__END__

=head1 NAME

Minimal example

=head1 SYNOPSIS

This is the synopsys section.

=cut
Run Code Online (Sandbox Code Playgroud)

运行脚本:

$ perl test.perl            
You need to install the perl-doc package to use this program.
use Pod::Usage qw(pod2usage);
pod2usage(-verbose => 2);

__END__

=head1 NAME

Minimal example

=head1 SYNOPSIS

This is the synopsys section.

=cut
Run Code Online (Sandbox Code Playgroud)

Mat*_*Moy 6

问题是pod2usage使用命令行程序perldoc.如果未安装此程序,则不会进行格式化,您将在输出中获得完整的源代码.

请注意,在问题中,文本" You need to install the perl-doc package to use this program."出现在输出中以提供有关正在发生的事情的提示(但是当帮助文本很长并通过管道传送到寻呼机时,此行并不总是可见).

解决方案:安装perldoc(例如apt install perl-doc在Ubuntu上).在这之后:

$ perl test.perl 
NAME
    Minimal example

SYNOPSIS
    This is the synopsys section.
Run Code Online (Sandbox Code Playgroud)