6

根据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

运行脚本:

$ 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
4

1 回答 1

7

问题是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.
于 2018-04-18T12:23:14.010 回答