karun.jiju has asked for the wisdom of the Perl Monks concerning the following question:

Suggest me a module to wrap the long text into 70 character lines. I tried the module text::format but it sometimes fails.Please find the code i tried below

use Text::Format; $body = "The Email Issue (matter getting shattering/ numbers coming in between etc..) was addressed to jiju and he is looking into this with + highest priority. This will be fixed ASAP."; $body = Text::Format->new({columns => 70,firstIndent => 0})->form +at($body); print $body;

Replies are listed 'Best First'.
Re: Perl Module to wrap the long text into 70 character lines.
by zentara (Cardinal) on Feb 16, 2010 at 13:39 UTC
    Try this:
    #!/usr/bin/perl -wT #won't increase line size, only decrease use strict; use Text::Wrap; die "\n\nusage: \n\t $0 <filename> [column width]\n" unless @ARGV==1 or @ARGV==2; open(FH,$ARGV[0]) or die "couldn't open $ARGV[0] $!"; $ARGV[0]=~ /^([-\@\w.]+)$/; # word chars only my $clean_out=$1; $clean_out eq $ARGV[0] or die "bad char in filename $ARGV[0]"; local $/= undef; # read entire file at once my @text=<FH>; close (FH); open(FH, '>',"$clean_out.wrap") or die "couldn't open ${clean_out}.wrap for writing"; $Text::Wrap::columns = $ARGV[1] || 70; print FH wrap('', '', @text); close(FH);

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku
Re: Perl Module to wrap the long text into 70 character lines.
by toolic (Bishop) on Feb 16, 2010 at 14:00 UTC
    I tried the module text::format but it sometimes fails.
    I tried your code, and it wraps at 70 characters. What do you mean when you say "it sometimes fails"? Can you show us an actual example of how it fails?