in reply to Re^4: Special formatting of error messages
in thread Special formatting of error messages

Bah! Looks like printf won't do centering. Have to calculate the space by hand. (As another responder posted...)

use strict; my @lines = <DATA>; my $maxsize = 0; map {chomp; $maxsize = ($maxsize>length)?($maxsize):(length)} @lines; print "max size: $maxsize\n"; my $windowSize = $maxsize +4; my $bar = '*' x $windowSize . "\n"; foreach (@lines) { # calculate space between this line and window border my $space = $maxsize - length($_); # determine if the space is an odd or even number my $odd = $space%2; # half the space will go on the left, half will # go on the left (plus one if it was odd). my $spacer = int($space/2); print($bar); print('* ' . ' ' x $spacer . $_ . ' ' x ($spacer + $odd) . " *\n"); print($bar); } __DATA__ some lines that are of different sizes Some small really small. ----------------some large--------------------- --------------------------------------------------some huge----------- +--------------------------------------- ...

"Look, Shiny Things!" is not a better business strategy than compatibility and reuse.