我有如下代码:
my $player_2ubid = grep { $_->ubid eq "2ubid" } @{$room_members };
my $player_3ubid = grep { $_->ubid eq "3ubid" } @{$room_members };
# ....
my $player_11ubid = grep { $_->ubid eq "11ubid" } @{$room_members };
为了避免重复,我想循环
for my $i ( 2 .. 11 ){
my $player_.$i.ubid = grep { $_->ubid eq "$i.ubid" } @{$room_members };
}
但是,这会产生语法错误:
Can't modify concatenation (.) or string in scalar assignment at ***.t line 100, near "};"
我在这里做错了什么?