in reply to
Neat format and word wrap
Or use Text::Table
#!
use strict;
use warnings;
use Text::Table;
my $title = "Shooter of US teen appears in court";
my $author = "Stephanie Kennedy";
my $date = "Fri, 13 Apr 2012 06:00:16";
my $content = "A Hispanic neighbourhood watch volunteer, charged with
+second-degree murder over the shooting death of an unarmed black teen
+ager in the United States, has appeared briefly in court for the firs
+t time.";
# "Cheap" wrapper
$content=~ s/(.{40}[^\s]*)\s+/$1\n/g;
my $tb = Text::Table->new(\"| ","",\" | ","",\" |");
$tb->load(
[ "TITLE",$title ],
[ "AUTHOR",$author ],
[ "DATE",$date ],
[ "CONTENT",$content ],
);
my $rule=$tb->rule('-', '+' );
for my $line ($tb->table) {
print $rule
unless ($line =~ /^\| +\|/);
print $line;
};
print $rule;
to get something like
+---------+---------------------------------------------+
| TITLE | Shooter of US teen appears in court |
+---------+---------------------------------------------+
| AUTHOR | Stephanie Kennedy |
+---------+---------------------------------------------+
| DATE | Fri, 13 Apr 2012 06:00:16 |
+---------+---------------------------------------------+
| CONTENT | A Hispanic neighbourhood watch volunteer, |
| | charged with second-degree murder over the |
| | shooting death of an unarmed black teenager |
| | in the United States, has appeared briefly |
| | in court for the first time. |
+---------+---------------------------------------------+