Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Neat format and word wrap

by trizen (Hermit)
on Apr 13, 2012 at 14:29 UTC ( #964935=note: print w/ replies, xml ) Need Help??

in reply to Neat format and word wrap

use 5.010; use Text::Wrap qw(wrap $columns); our $columns = 57; # change this my $hbar = q{-} x ($columns + 12); # DON'T change this printf "%s\n| TITLE |%-${columns}s| %s\n| AUTHOR |%-${columns}s| %s\n| DATE |%-${columns}s| %s\n| CONTENT |%-${columns}s| %s\n", map({ if (/\n/) { s{^(.*)\K\n} { sprintf("%*s\n|", $columns - length($1), '|'). q{ } x (length($hbar)-$columns-3). q{| } }egm; s{\n\|\h+\|(.*)\K\z} { sprintf '%*s', $columns - length($1), q{ } }e; s{\A(.*)\K\|$}{length($1)<$columns ? q{ |} : q{|}}em; } $_ } map({$hbar, q{ } . wrap(q{}, q{}, $_)} $title, $author, $date, $content),$hbar);

Comment on Re: Neat format and word wrap
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2016-02-08 23:25 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (290 votes), past polls