How can I use a variable as a variable name in Perl?

前端 未结 3 1463
离开以前
离开以前 2020-11-22 14:48

I need to achieve the following in perl

printmsg(@val1, $msg1) if @val1;
printmsg(@val2, $msg2) if @val2;
printmsg(@val3, $msg3) if @val3;
printmsg(@val4, $m         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 15:09

    You can't just string variables together like that and get a resulting variable. You COULD evaluate the expression of $msg + i, but it's probably better if you make msg an array and just index: $msg[$i].

提交回复
热议问题