|laziness, impatience, and hubris|
How to avoid "Use of uninitialized value" with printf?by bobdabuilda (Beadle)
|on Apr 05, 2012 at 06:10 UTC||Need Help??|
bobdabuilda has asked for the
wisdom of the Perl Monks concerning the following question:
Hi guys. Have been working on a bit of a toy utility for myself to fill in a bit of downtime. Part of it involves interrogating a system, and dumping to screen a list of values, in column format.
A snippet of the code I'm using is shown below:
Now, whilst manipulating and testing the above to get it runnable for display here, I *may* have realised part of what the issue is... but there's still a ?? around part of it.
I'm thinking that, where the script is splitting the data, effectively, into rows of 6... when there aren't 6 items - as per the above example, on the second pass - it gives 3 instances of the "Use of uninitilized value in printf" error - which with this example equate to the 3 values that aren't there for the printf command on the second pass.
Sounds right so far, yeah? The only problem I have at this point, is that when running it with the full set of data, it gets around 90% of the way through, dumps out 4 of those errors, and then prints 2 more values at the end... which kind of blows my theory out of the water...
However - on having another look at the results, the 4 errors being spat out are after a "complete" line is printed, followed by the last 2 values. That equals 6 items, which is how many it's trying to print. Is printf somehow filling the %-12s from right to left for some reason, perhaps??
Please help me demistify this issue...