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

I have been using Text::Wrap to convert text files for viewing on a PDA. For some reason, when I convert files which contain words that exceed the Columns Limit in $Text::Wrap::columns, that word does not appear after conversion.

URLs and some Words(antidisestablishtarianism) do not appear in most of these conversions.

Is there something I'm missing when reading files?

This is the code I"m using:

use Text::Wrap; $file = $ARGV[0]; open(FILE,$file); @text = <FILE>; close FILE; open(FH,">new$file"); $Text::Wrap::columns = 40; print wrap('','',@text);
Thanks.

Replies are listed 'Best First'.
Re: Text::Wrap and Long words
by Zaxo (Archbishop) on Jul 31, 2003 at 02:35 UTC

    That works for me. What is the value of $Text::Wrap::huge? If set to 'wrap', Text::Wrap will break a long word up at the column limit. Do you have an old version? 'wrap' is the default in mine.

    If that looks ok, you might try setting $Text::Wrap::columns to one or two less than the screen width. The target may not treat "\n" as zero width.

    After Compline,
    Zaxo

Re: Text::Wrap and Long words
by graff (Chancellor) on Jul 31, 2003 at 03:00 UTC
    I tried your code with the following setup:
    INST_FILE /usr/local/lib/perl5/5.8.0/Text/Wrap.pm INST_VERSION 2001.0929
    and with the following sample data file:
    Here is a sample file that contains longish lines of text to be wrapped. It also contains really long words, for example: superantidisestablishmentarianismabilityness, which weighs in at 45 characters (I think), counting the comma.
    and that yielded the following:
    Here is a sample file that contains longish lines of text to be wrapped. It also contains really long words, for example: superantidisestablishmentarianismabilit yness, which weighs in at 45 characters (I think), counting the comma.
    (Note that the last six characters of the long word were wrapped to the next line -- not five -- because Text::Wrap's notion of "column width" includes the line termination as part of the maximum allowed length.)

    So, I'm not seeing the problem you mention (the big word didn't just disappear -- it's still there, and is split into pieces according to the allowed max width). Maybe there's some other step in trip to your palm pilot where something is getting lost?

    Personally, I find the "picket-fence" effect demonstrated with my test file to be really annoying -- it works better if you do chomp @text; before passing the array to "wrap()".

    update: BTW, I assume your real code does print FH wrap(...); -- not just "print wrap(...)".