以下脚本智能匹配两个数组的切片.一开始,两个阵列都是一样的,我得到了合理的结果.然后我改变其中一个数组并智能匹配两个新切片,但它仍然说切片是相同的.但是,当我将切片复制到数组中时,对数组进行智能匹配表明它们确实不同.
剧本:
#!/usr/bin/perl
use warnings;
use strict;
use diagnostics;
my @x = qw (one two);
my @y = qw (one two);
my @x_s;
my @y_s;
print "Before change: values are the same:\n";
@x_s = @x[0,1];
@y_s = @y[0,1];
print "\@x_s: @x_s\n";
print +(@x[0,1] ~~ @y[0,1]) ? "equal\n" : "not equal\n";
print +(@x_s ~~ @y_s) ? "equal\n" : "not equal\n";
$x[0]='three';
print "After change: values should be different:\n";
@x_s = @x[0,1];
@y_s = @y[0,1];
print "\@x_s: @x_s\n";
print +(@x[0,1] ~~ @y[0,1]) …Run Code Online (Sandbox Code Playgroud)