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

Thanks for the explanation, you correctly identified the area I was having problems with and have explained it fully.
Cheers,
Ronnie
PS I just need to find out how to centre the text now.
  • Comment on Re^4: Special formatting of error messages

Replies are listed 'Best First'.
Re^5: Special formatting of error messages
by osunderdog (Deacon) on Feb 02, 2005 at 16:05 UTC

    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.