4

天,

为什么我从下面的脚本片段中收到以下两个错误?

参数“www4.mh.xxxx.co.uk.logstatsto20090610.gz”在第 56 行的除法 (/) 中不是数字

参数“/logs/xxxx/200906/mcs0.telhc/borg2”在第 56 行的除法 (/) 中不是数字

变量 $dir 和 $log 都是字符串,两个字符串的连接以及中间的斜线也用引号引起来。

        foreach my $dir (@log_dirs) {
            foreach my $log (@log_list) {
line 56:        if ( -s "$dir/$log" ) {
                    push(@logs, $dir/$log);
                }
            }
        }

编辑:第 56 行绝对是 if 语句。但是,Paul,您是对的,将第57 行的除法用引号括起来可以解决问题。谢谢。

编辑:报告第 56 行的 Perl 版本是

stats@fs1:/var/tmp/robertw> /usr/local/perl/bin/perl -v      

This is perl, v5.6.1 built for sun4-solaris

Copyright 1987-2001, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'.  If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.

stats@fs1:/var/tmp/robertw> 

编辑:虽然在 Perl 中使用插值字符串的方法,但考虑到变量本身就是字符串,并且我试图用斜杠字符将它们连接在一起,这不是最终结果字符串连接吗?

干杯,

4

4 回答 4

12

第 56 行可能是它之后的行,您确实尝试在其中分割两个字符串。你可能的意图是

   foreach my $dir (@log_dirs) {
        foreach my $log (@log_list) {
            if ( -s "$dir/$log" ) {
                push(@logs, "$dir/$log");
            }
        }
    }
于 2009-06-11T12:37:17.520 回答
9

您没有在push中引用字符串。与其自己创建路径,不如尝试养成使用File::Spec创建可移植路径的习惯:

use File::Spec::Functions;

my $path = catfile( $dir, $file );

然后,您可以$path在需要该字符串的任何时候使用,这样您就不会通过再次重新制作字符串来重复自己(并且下次可能做错了;)。

于 2009-06-11T12:37:36.897 回答
5

这是由以下行引起的:

push(@logs, $dir/$log);

你在那里有一个部门。

于 2009-06-11T12:37:53.777 回答
2

我很想知道您使用的是哪个版本的 perl?我可以轻松尝试的所有方法都正确报告了推送的行号。

于 2009-06-11T14:28:15.023 回答