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
If I understand, you need "eval"!
for(my $i=1; $i < 6; $i++ ) {
eval 'printmsg(@val'. $i . ', $msg' . $i .') if @val' . $i;
}
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?