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.
If I understand, you need "eval"!
But remember! All variable(@val1, @val2, ..., @valN) must exists! As you're not providing too much of your code I'm unavaiable to infer more about this problem. Maybe you could provide more code huh?