logo       

Re: format a variables value for print: msg#00368

perl-beginners

Subject: Re: format a variables value for print

On Sun, Jul 26, 2009 at 17:37, Harry Putnam<reader@xxxxxxxxxxx> wrote:
> I'm a little lost even what to look for to do this.
>
> With a variable like this:
>
> $var = 'American Express offers individuals online access to its world-class
> Card, Financial, and Travel services, including financial advice, retirement
> planning, air and hotel reservations and more'
>
> I never know how many words will be in the content.
>
> What can I do to format the output info something like 70 characters
> per line (not splitting any words) and each line to begin with 4
> spaces.

I believe you want either [Text::Wrap][1] (which has been a part of
the core since Perl 5.2):

#!/usr/bin/perl

use strict;
use warnings;

use Text::Wrap;

my $var = 'American Express offers individuals online access to its
world-class Card, Financial, and Travel services, including financial
advice, retirement planning, air and hotel reservations and more';

my $indent = " " x 4;
$Text::Wrap::columns = 70;
print wrap($indent, $indent, $var), "\n";

[1] : http://perldoc.perl.org/Text/Wrap.html


--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
http://learn.perl.org/


Google Custom Search

News | Mail Home | sitemap | FAQ | advertise