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...


In reply to How to avoid "Use of uninitialized value" with printf? by bobdabuilda

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.