Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://964935]
[marto]: I'm sure it's only going to be a matter of hours before someone adds that comment
[marto]: or closes the question because it's a almost the same as one someone else asked, years ago...
[marto]: snackoverflow gamification of editorial powers for the win :/
marto should register snarkoverflow
[marto]: nothing to see here people, go about your daily business :P

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2018-01-23 10:45 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (243 votes). Check out past polls.