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, $msg4) if @val4;
printmsg(@val5, $msg5) if @val5;
printmsg(@val6, $msg6) if @val6;
So i wrote the following snippet
for(my $i=1; $i < 6; $i++ ) {
printmsg(@val$i, $msg$i) if @val$i;
}
It doesn't work and breaks out with errors.