perl - 为什么这种预期的插值被解释为 Perl 的除法?

标签 perl string-interpolation

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

Argument "www4.mh.xxxx.co.uk.logstatsto20090610.gz" isn't numeric in division (/) at line 56

Argument "/logs/xxxx/200906/mcs0.telhc/borg2" isn't numeric in division (/) at line 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 语句。然而,保罗,你是对的,用引号将第 57 行的除法括起来解决了这个问题。谢谢。
编辑: Perl 版本报告第 56 行是
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 中使用了内插字符串的方法,但鉴于变量本身就是字符串并且我试图用斜杠字符将它们连接在一起,这不是最终结果字符串连接吗?
干杯,

最佳答案

第 56 行可能是它之后的那一行,在那里您确实尝试将两个字符串分开。你可能想要的是什么

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

关于perl - 为什么这种预期的插值被解释为 Perl 的除法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/980824/

相关文章:

perl - WWW::Mechanize::Firefox 超时

macos - Alien::wxWidgets 在 OSX 10 上安装失败

python /珀尔 : timed loop implementation (also with microseconds)?

mysql - perl DBIx::类::架构

scala - 动态字符串插值

css - LESS 类名字符串插值不起作用

python - str.format() 具有两种对齐方式 { :>} and variable interpolation

ios - Swift 3 中的字符串插值段错误

perl - 如何将 $_ 的值更改为 perl 中 grep 中所需的值?

javascript - 如何在 Vue.js 中的模板元素中进行字符串插值?