Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Neat format and word wrap

by clueless newbie (Friar)
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 drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2014-07-13 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (247 votes), past polls