|Just another Perl shrine|
Format, empty vars, and fixed-width recordsby kwaping (Priest)
|on Apr 21, 2008 at 22:33 UTC||Need Help??|
kwaping has asked for the
wisdom of the Perl Monks concerning the following question:
I need to output data to a fixed-width record file. The lines need to be exactly 129 characters long. I thought format would be great for this, and it has been - except for one issue... The line only prints up to the last variable that contains a non-pad character. My current code runs out of data at position 92, after which everything is undef. That is also where the output line ends. Unfortunately, I need it to pad out to the 129 character requirement.
Can anyone help? Here's what I've tried already:
I also tried using sprintf, but if the data is longer than intended, the line becomes too long. I'd rather not substr and sprintf every piece of data, but I'll do it if that's what's required.
Example code (disregard unintialized and "not a number" warnings):
Update: I've decided to go with the substr(sprintf()) method after all. Not the prettiest or most elegant, but it works.
It's all fine and dandy until someone has to look at the code.