Command printf prints last column close to previous column left justified (but with inadequate spacing). I think this is the format I need. However, changing number in printf for last column to get better alignment under folder access heading doesn't increase spacing until column jumps to next line abruptly.
That's the first obvious mistake, but if you specify the correct format length, which is the combined total of those 3 fields, it should be ok. It appears that the correct length would be between 60 and 68 depending on the desired spacing prior to the next field. You've specified a field length of 8, which is clearly not even close to what it should be.
After a couple tests, this might be closer to what you need.
However, although you modify numbers I still get similar result when I change -38 to 38, tested before I opened this new thread. Last column values are aligned under last column header, but right aligned.
Your code for last column values gives right alignment as oppose to left alignment (correct format that I need) to make report more appropriate.
Based on printf formatting it should give left alignment for -30, but isn't. Any ideas why and what is solution?
If you put some delimiters around each field's format specification, you'll be able to see more clearly the leading and trailing spaces between the fields. Based on that info, you should be able to see what adjustments you need to make.
You haven't clearly stated how the columns should line up, but Here's my test script which I think gives the output you desire.
Code:
#!/usr/bin/perl
use strict;
use warnings;
print <<'HEADER';
----------------------------------------------------------------------------------------------------------
domain\username full name last access date last access (days) folder access
----------------------------------------------------------------------------------------------------------
HEADER
my $original_line = 'test\JOHN123 John Campbell Fri 10-19-2012';
my $result = 59;
my $user_folders = 'EDITOR';
printf ("%-67s %-22.0f %-14s\n", $original_line, $result, $user_folders);
Outputs:
Code:
----------------------------------------------------------------------------------------------------------
domain\username full name last access date last access (days) folder access
----------------------------------------------------------------------------------------------------------
test\JOHN123 John Campbell Fri 10-19-2012 59 EDITOR