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

I can't get Text::Wrap to work when the word is longer than the $columns. If one word is longer than the max width/columns, it kills the program and prints a blank screen. Can someone tell me why this isn't working or what module would break up a single word like "aaaaaaddfgfgdfgrergdgfddgreergdfgdfredfg" down to X columns and wrap the rest? I've tried
$Text::Wrap::columns = 30; $one = wrap('', '', $one); $two = wrap('', '', $two); $three = wrap('', '', $three);

Title edit by tye

Replies are listed 'Best First'.
Re: Text::Wrap
by antirice (Priest) on Jul 29, 2003 at 01:42 UTC

    Set $Text::Wrap::huge = "wrap";. Here's the documentation for more info.

    antirice    
    The first rule of Perl club is - use Perl
    The
    ith rule of Perl club is - follow rule i - 1 for i > 1

      use Text::Wrap qw(wrap $columns $huge); $columns = 132; # Wrap at 132 characters $huge = 'wrap';
      but again, if the text is one word and exceeds that limit, it makes the entire script crash and not produce any source code other than the headers.

        Well, we need more info then. What version are you using? Have you reduced the script so you check only Text::Wrap? Also, you said the script errors out and crashes. What's the exact message? As it stands, what you have posted should work.

        antirice    
        The first rule of Perl club is - use Perl
        The
        ith rule of Perl club is - follow rule i - 1 for i > 1

Re: Text::Wrap
by BUU (Prior) on Jul 29, 2003 at 02:14 UTC
    what about just s/(\S{40})/$1 /g; .. or is that too simple and we have to use a module =/
      I tried your script and it didn't change the outcome of anything. Atleast it didn't error out, but it didn't break the text apart :(
        You specified a column width of 30. His suggestion was to break it at 40, which you said still didn't work. Try using his tip to break it at 29?

        Or could you PLEASE show us some actual example input, and a really short but complete snippet which will demonstrate the wrong behavior? Monks at this site bend over backwards to help, even when the questioner isn't giving much useful information to go on. But there are limits.

        --
        [ e d @ h a l l e y . c c ]