matua105 has asked for the wisdom of the Perl Monks concerning the following question:

Hello most esteemed monks:

Text wrap is not working in my environment. Here is the code:

use Text::Wrap qw(wrap $columns $huge); $columns = 40; $huge = 'wrap'; print wrap;

This is based on the examples at perldoc.perl.org/Text/Wrap.html

Most likely I am doing something wrong here. Thanks in advance for your help.

Replies are listed 'Best First'.
Re: Text::Wrap not working
by toolic (Bishop) on Aug 23, 2010 at 18:38 UTC
    That's because you didn't pass anything to the wrap function:
    use strict; use warnings; use Text::Wrap qw(wrap $columns $huge); $columns = 40; $huge = 'wrap'; my $text = 'break up this really long sentence for me please'; print wrap('', '', $text); __END__ break up this really long sentence for me please

    See more EXAMPLES.

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

Re: Text::Wrap not working
by Your Mother (Archbishop) on Aug 23, 2010 at 18:36 UTC

    I think I found a related issue. It seems that print isn't working in my environment. No output!

    print;

    Maybe that'll help you spot your issue. :)

      Weird, for me, that prints lots!
      $_ = 'lots'; print;

      :)

Re: Text::Wrap not working
by TomDLux (Vicar) on Aug 23, 2010 at 18:35 UTC

    Doesn't wrap() take an argument, the string you want to print?

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.