Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
就像我们如何使用正则表达式匹配变量一样,我想使用正则表达式将可变长度分配给我的变量。
例如:让我们使用一个计数器$i,它$i在 for 循环中运行
$i
for($i=0; $i < 256; $i++) { $myVariable = a{$i}; }
我想要$myVariable不同的长度,基于计数器变量$i
$myVariable
例如,如果$i是 5,那么$myVariabe应该是"aaaaa"
$myVariabe
"aaaaa"
for my $i (1..255) { my $myVariable = 'a' x $i; ... }
或者
my $myVariable; for my $i (1..255) { $myVariable .= 'a'; ... }