在perl中使用pod2usage时出现编译错误

时间:2015-03-24 05:43:45

标签: perl

我有一个文件接受一个文件作为参数并对其进行一些操作。

#!/usr/bin/perl    
use strict;
use warnings;
use Date::Format;
use Pod::Usage;

###################
#USAGE
###################

=head1 SYNOPSIS

perl my-file.pl <log file name>

     Options:
       -help            Prints usage synopsis of this program.
       -man         Man page for this program.

Use option "-man" for extended usage help.

=head1 ARGUMENTS 

=over 1

=item 1 Log File Name

Enter name of the log file. This is a required argument.

=cut

print "\n\n";
GetOptions('help|?' => \$help, man => \$man) or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-verbose => 2) if $man;
pod2usage("$0: Insufficient arguments given. Please see the usage below...")  if (@ARGV == 0);  

my $logfile = $ARGV[0];    
my $cmd;
my $n;
$cmd = q(awk '!/Jobs still running./' $logfile > temp.txt && mv temp.txt $logfile);
$n = system($cmd)

运行此文件时,我收到以下编译错误。不确定这个错误的原因是什么,因为具有类似格式的另一个文件工作正常。

Global symbol "$help" requires explicit package name at mv-workitem-LogWatcher.pl line 33.
Global symbol "$man" requires explicit package name at mv-workitem-LogWatcher.pl line 33.
Global symbol "$help" requires explicit package name at mv-workitem-LogWatcher.pl line 34.
Global symbol "$man" requires explicit package name at mv-workitem-LogWatcher.pl line 35.
my-file.pl had compilation errors

2 个答案:

答案 0 :(得分:0)

您已启用strict但未能声明您的变量。您通常使用my执行此操作。这是some more about my and lexical scoping of variables

我建议您选择Modern PerlBeginning Perl

的副本

答案 1 :(得分:0)

您收到错误是因为您在代码中使用use strict但未声明任何varibale。

要理解变量声明,请阅读本教程Variable declaration in Perl