Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl Pod::用法帮助格式化_Perl_Options_Command Line Interface - Fatal编程技术网

Perl Pod::用法帮助格式化

Perl Pod::用法帮助格式化,perl,options,command-line-interface,Perl,Options,Command Line Interface,我想为我的Perl脚本正确设置帮助消息的格式,如果可能的话,可以使用标准模块,如Pod::Usage。不幸的是,我并不真正喜欢pod2usage的输出格式。例如,使用grep我可以获得以下帮助结构: $ grep --help Usage: grep [OPTION]... PATTERN [FILE]... Search for PATTERN in each FILE or standard input. PATTERN is, by default, a basic regular exp

我想为我的Perl脚本正确设置帮助消息的格式,如果可能的话,可以使用标准模块,如
Pod::Usage
。不幸的是,我并不真正喜欢pod2usage的输出格式。例如,使用
grep
我可以获得以下帮助结构:

$ grep --help
Usage: grep [OPTION]... PATTERN [FILE]...
Search for PATTERN in each FILE or standard input.
PATTERN is, by default, a basic regular expression (BRE).
Example: grep -i 'hello world' menu.h main.c

Regexp selection and interpretation:
  -E, --extended-regexp     PATTERN is an extended regular expression (ERE)
  -F, --fixed-strings       PATTERN is a set of newline-separated fixed strings
  -G, --basic-regexp        PATTERN is a basic regular expression (BRE)
  -P, --perl-regexp         PATTERN is a Perl regular expression
但是这与
Pod::Usage
非常不同,我得到了不需要的
\n
\t

$ ./sample.pl --help
Usage:
    sample [options] [file ...]

    This program will read the given input file(s) and do something useful
    with the contents thereof.

Options:
    --help
        Print a brief help message and exits.

    --man
        Prints the manual page and exits.
我想以传统方式修改我的帮助格式,即不使用
\n
和不使用
\t
。事实上,我正在寻找一种解决方案,使我能够写下以下内容:

__END__

=head1 SYNOPSIS

sample [options] [file ...]

B<This program> will read the given input file(s) and do something
useful with the contents thereof.

=head1 OPTIONS

=item B<-h,--help>
    Print a brief help message and exits.

=item B<-v,--version>
    Prints the version and exits.

=cut 
不是这个:

Usage:
    sample [options] [file ...]

    This program will read the given input file(s) and do something useful
    with the contents thereof.

Options:
    -h,--help Print a brief help message and exits.
    -v,--version Prints the version and exits.

有线索吗

您可以尝试两件事:

用户需要将其切换到Pod::Text,这是一个更简单的格式化程序


Pod::Text
也有一些格式选项,例如左边距、缩进级别、页面宽度,这可能会使它更符合您的喜好。

当您使用
=item
时,您应该在它前面加上
=over x
,其中
x
是您要移动的距离。完成项目后,需要使用
=back
。如果
=over x
足够长,则该项目的段落将与
=item
打印在同一行上。我到处玩,发现
=20多个
看起来很不错:

use strict;
use warnings;

use Pod::Usage;

pod2usage( -verbose => 1);

=pod

=head1 SYNOPSIS

    sample [options] [file ...]

B<This program> will read the given input file(s) and do something
useful with the contents thereof.

=head1 OPTIONS

=over 20

=item B<-h>, B<--help>

Print a brief help message and exits.

=item B<-v>, B<--version>

Prints the version and exits.

=back 

=cut 
在POD中使用
v,-version
的东西并不能让它以漂亮的三列格式打印。您可以做的是在
-h
-help
之间留出更多的空间,就像我在上面所做的那样,以提高可读性

记住,重要的是POD中的数据,而不是绝对格式。使用格式使其易于阅读,但不要过分强调细节

我强烈建议您使用旧的标准手册页布局(这是
pod2use
假定的)

use strict;
use warnings;

use Pod::Usage;

pod2usage( -verbose => 1);

=pod

=head1 SYNOPSIS

    sample [options] [file ...]

B<This program> will read the given input file(s) and do something
useful with the contents thereof.

=head1 OPTIONS

=over 20

=item B<-h>, B<--help>

Print a brief help message and exits.

=item B<-v>, B<--version>

Prints the version and exits.

=back 

=cut 
Usage:
        sample [options] [file ...]

    This program will read the given input file(s) and do something useful
    with the contents thereof.

Options:
    -h, --help          Print a brief help message and exits.

    -v, --version       Prints the version and exits.