【发布时间】:2014-11-05 13:53:36
【问题描述】:
我遇到了一些我不明白的事情,这是我的代码:
@iprouteur = split( /./, $arraylist[1] );
print "lip du routeur est $arraylist[1]\n";
for ( $i = 2; $i <= $#arraylist; $i++ ) {
print "we found secondary which is $arraylist[$i]\n";
@secondary = split( /./, $arraylist[$i] );
print "voici les ip a comparer : $iprouteur[0] $iprouteur[1] $iprouteur[2] et $secondary[0] $secondary[1] $secondary[2] \n";
if ( $iprouteur[0] eq $secondary[0] && $iprouteur[1] eq $secondary[1] && $iprouteur[2] eq $secondary[2] ) {
print "we need to splice \n";
}
}
输出是这样的:
lip du routeur est 126.x.x.x
we found secondary which is 126.x.x.x/24
voici les ip a comparer : et
we need to splice
为什么 perl 找不到 $iprouteur[x] 和 $secondary[y] 变量中的内容?
【问题讨论】:
-
有趣的事实:当您插入一个数组(切片)时,元素之间用空格分隔。所以你可以做
" ... @ipproteur[0,1,2] .." -
你在使用
use strict; use warnings;吗? -
你的意思是我可以使用 if (@iprouteur[0,1,2] eq @secondary[0,1,2]) ?
-
不,我的意思是它所说的,您可以将它们插入双引号字符串中。例如。
print "@foo[0,1,2]"与print "$foo[0] foo[1] $foo[2]"相同