0

I would like to restrict the column number to 45 characters. I am using the Text::Wrap:wrap as below.

$Text::Wrap::columns = 44;
print FOUT wrap('','' ,<FIN>);

It is making all the colums to 44 chars without word breakage. But it is reducing spaces for some of the lines at the begining.

Text before using wrap():

EVENTS: KINJHK QDFMED QDFMED
        QDFMED KINJHK QDFMED
        KINJHK

BUTIONS: 52314 KINJHK KINJHKQDFMED
         QDFMED42 KINJHK524 MBCXZ
         56.321 ILOLKI 421

TeXt after using wrap()

EVENTS: KINJHK QDFMED QDFMED
      QDFMED KINJHK QDFMED
      KINJHK

BUTIONS: 52314 KINJHK KINJHKQDFMED
      QDFMED42 KINJHK524 MBCXZ
      56.321 ILOLKI 421

For example in the EVENTS section the spaces are reduced before the line QDFMED KINJHK QDFMED and the below lines. But I want the alignment should not be disturbed after using wrap() method.

I have tried many ways of using this wrap, but no use. Could any please help me.

Thanks. Vis.

4

1 回答 1

2

您使用的是哪个版本的 Text::Wrap 模块?使用 2009.0305 如

#! /usr/bin/env perl

use strict;
use warnings;

use Text::Wrap;

# demo only
*FIN = *DATA;
*FOUT = *STDOUT;

$Text::Wrap::columns = 44;
print FOUT wrap('', '', <FIN>);

__DATA__
EVENTS: KINJHK QDFMED QDFMED
        QDFMED KINJHK QDFMED
        KINJHK

BUTIONS: 52314 KINJHK KINJHKQDFMED
         QDFMED42 KINJHK524 MBCXZ
         56.321 ILOLKI 421

产生您想要的输出并且不会减少缩进。

事件:KINJHK QDFMED QDFMED
        QDFMED KINJHK QDFMED
        金杰香港

BUTIONS: 52314 KINJHK KINJHKQDFMED
         QDFMED42 KINJHK524 MBCXZ
         56.321 伊洛基 421

注意:代码中的所有空格都是空格字符,没有制表符。但是,用前导 TAB 字符替换空格对输出没有影响。

也许您的代码中还有其他一些我们还不知道的重要上下文。

于 2012-06-06T10:52:23.473 回答