假设你有:
my $data1 = [
+{ id => 1, name => 'A' },
+{ id => 2, name => 'B' },
+{ id => 3, name => 'C' },
+{ id => 4, name => 'A' },
# .... many rows
];
作为输入。
每次名称为“A”(名称=>“A”)时,我都想将 id 更改为 1(id =>1)。循环是完全必要的吗?
# loop
if ( $data1->[#what to put here?]->{id} = 1 ) {
$data1->[#what to put here?]->{name} = 'A';
}
这该怎么做?