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.
似乎在 foreach 外部声明的变量,在 foreach 内部初始化的变量不会保留其数据。
考虑这个例子:
[- $myVar; foreach my $item (qw/item1 item2 item3/) { $myVar = $item; } print $myVar # This will print undef, I expect it to print item3 -]
如何使用 foreach 循环进行这项工作?
print $myVar将句子更改为print OUT $myVar; OUT 文件句柄与 Embperl 的输出流相关联。您也可以使用[+ $myVar +]块而不是打印到 OUT。
print $myVar
print OUT $myVar;
[+ $myVar +]