in reply to Re: Text::Wrap not working
in thread Text::Wrap not working

Thanks toolic. I used Example 3 but it is still not working. I am thinking it has to do with the rest of the code.

use Text::Wrap; $text = $message; @lines = split(/\n/, $text); $lCnt .= $#lines+1; $lineStart = 80; $lineHeight = 24; $Text::Wrap::columns = 35; print wrap('','',@text);

Replies are listed 'Best First'.
Re^3: Text::Wrap not working
by toolic (Bishop) on Aug 23, 2010 at 21:00 UTC
    Your new code doesn't work because you never assigned any values to your @text array. This error would have been caught if you use strict and warnings. I wonder if you really meant:
    print wrap('','',@lines);

    Did the code in my original reply work for you?

      Hi toolic:

      Your original example did not work for me. Many of the variables are being passed via html user input. Thus message is:

      $message = $q->param('message');

      Message is obtained from a textarea box that is embedded on an image and is sent via sendmail in the cgi. The problem is the text is not wrapping in the image box.

        GD::Text::Wrap is frequently used with CGI. Maybe you should try it. For example:
        #!/usr/bin/perl use strict; use warnings; use GD; use GD::Text::Wrap; my $gd = GD::Image->new(800,600); my $text = <<EOSTR; This is the way it is. This is the way it was. EOSTR my $wrapbox = GD::Text::Wrap->new( $gd, text => $text); $wrapbox->set_font(gdMediumBoldFont); $wrapbox->set_font('arial', 12); $wrapbox->set(align => 'left', width => 40); $wrapbox->draw(10, 140); print "\n$text\n";