How to perform dynamic formatting with perl during write?
- by Bee
I have a format which is defined like below:
format STDOUT =
------------------------------------
|Field1 | Field2 | Field3 |
------------------------------------
|@<<<<<<<<<<| @<<<<<<<<<<<| @<<<<< |~~
shift(@list1),shift(@list2),shift(@list3)
------------------------------------
.
write STDOUT;
So the questions are as below:
Is it possible to make the list of values printed dynamic?
e.g. If list 1 contains 12 elements, and if $flag1 is defined, then print only elements 0..10 instead of all 12. I tried doing this by passing $flag as a parameter to the sub which generates the report. However, the last defined FORMAT seems to always take precedence and the final write when it happens, applies the last format no matter what the condition is.
Is it possible to also add/hide fields using the same process. e.g. If $flag2 is defined, then add an additional field Field4 to the list?