in reply to Specifiying a Range for Variables?
There are also ways to do one eval of '($cmd1, $cmd2, $cmd3, $cmd4)', but I can't think of a way that does not require using a temporary variable like this:$cmd1 = 'This'; $cmd2 = 'Is'; $cmd3 = 'a'; $cmd4 = 'test'; my @cmds = map{eval '$cmd'.$_} (1..4);
Update Just realised from reading Mr Muskrat's post below that you can interpolate and then use that to get another variable. Hence this may be your best versionmy $t='('; $t.= "\$cmd$_, " for (1..4); @cmds = eval $t.')';
$cmd1 = 'This'; $cmd2 = 'Is'; $cmd3 = 'a'; $cmd4 = 'test'; my @cmds = map{ ${"cmd$_"} }(1..4);
Dingus
|
|---|