Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Neat format and word wrap

by clueless newbie (Hermit)
on Apr 13, 2012 at 14:41 UTC ( #964938=note: print w/ replies, xml ) Need Help??


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. | +---------+---------------------------------------------+


Comment on Re: Neat format and word wrap
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://964938]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2015-07-29 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls