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

Yes that was the original idea that I had but ..... (Now this may be the daftest part of the question) how is the space padding applied? Cheers, Ronnie PS I may be missing something very obvious here but for the life of me I can't see it!
  • Comment on Re^2: Special formatting of error messages

Replies are listed 'Best First'.
Re^3: Special formatting of error messages
by davido (Cardinal) on Feb 02, 2005 at 17:11 UTC

    I kind of described it already, but here's one brainstorm that is untested:

    use strict; use warnings; my $string = <<HERE; A long time ago in a galaxy far far away a great adventure took place. HERE sub textbox { my( @lines ) = split /\n/, $_[0]; chomp @lines; my $longest = 0; foreach my $line ( @lines ) { my $size = length $line; $longest = $size if $size > $longest; } foreach my $line ( @lines ) { my $prepad = ' ' x ( ( $longest - length( $line ) ) / 2 ); $line = $prepad . $line; $line .= ' ' x ( $longest - length( $line ) ); $line = '* ' . $line . ' *'; } my $outline = '*' x ( $longest + 4 ); push @lines, $outline; unshift @lines, $outline; return join( "\n", @lines ) . "\n"; } print textbox( $string );

    This could use some streamlining, but I left it reasonably verbose so that it would be clear what's going on. Enjoy!


    Dave