Perl:

use 5.016;
use Data::Dump qw/dump/;

my @rocks = qw/r1 r2 r3/;

foreach my $rock (@rocks) {
    $rock .= "s";
}

say dump @rocks;

输出结果:

("r1s", "r2s", "r3s")

Python:

rocks = ['r1', 'r2', 'r3']

for rock in rocks:
    rock += 's'

print rocks

输出结果:

['r1', 'r2', 'r3']

我想说的是, Perl 的 foreach 竟然能改变原列表里面的值, 果然是令我大吃一惊...

Comments
Write a Comment