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:
my @UACS; # open(POLICY, "getpol -t UACS |"); commented - replaced by __DATA_ +_ for this example my $pol; while (<DATA>) # ($pol = <POLICY>) <== could this be changed to wh +ile (my $pol = <POLICY>), to remove the previous line ?? { chomp $_; # was $pol my($type,$number,$name); ($type, $number, $name) = split (/\|/, $_, -1); chomp $name; push(@UACS,$name); } @UACS = sort(@UACS); while (@UACS) { my @rows = splice(@UACS, 0, 6); printf "%-12s %-12s %-12s %-12s %-12s %-12s\n", @rows; } print "\nPress ENTER to continue..."; my $a = <STDIN>; # close(POLICY); commented - superfluous due to __DATA__ for this e +xample __DATA__ UAC|10|ADMIN|Description1| UAC|20|CIRC|Description2| UAC|30|CIRCADMIN|Description3| UAC|40|CIRCBEE|Description4| UAC|50|CIRCBRO|Description5| UAC|60|CIRCBUR|Description6| UAC|70|CIRCBUW|Description7| UAC|80|CIRCCAS|Description8| UAC|90|CIRCCOM|Description9|
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...
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |