【发布时间】:2018-05-22 15:52:14
【问题描述】:
我在 Perl 中有一个简单的 foreach 循环,它登录到几个不同的远程主机并运行一个返回数值的命令。我想将此值保存到变量中。该变量将以各个主机名(正在循环)命名, 如下:
host01_backup
host02_backup
等等……
因此我的问题 - 是否可以在循环中执行此操作。
foreach $i (@hosts) {
print "hostname is: $i \n";
ssh("ins\@$i", "$cmd"); # this is where I want to assign a variable which is part named using the contents of $i (hostname).
提前干杯!
【问题讨论】:
标签: perl variables for-loop scripting