Perl:无法按照确切要求使用 Text::Wrap:wrap() [英] Perl : Couldn’t use Text::Wrap:wrap() as per exact requirement

查看:41
本文介绍了Perl:无法按照确切要求使用 Text::Wrap:wrap()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将列号限制为 45 个字符.我正在使用 Text::Wrap:wrap 如下.

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

它使所有的列都变成了 44 个字符而不会出现断字.但它减少了开头部分行的空间.

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.

使用wrap()前的文字:

Text before using wrap():

EVENTS: KINJHK QDFMED QDFMED
        QDFMED KINJHK QDFMED
        KINJHK

BUTIONS: 52314 KINJHK KINJHKQDFMED
         QDFMED42 KINJHK524 MBCXZ
         56.321 ILOLKI 421

使用wrap()

EVENTS: KINJHK QDFMED QDFMED
      QDFMED KINJHK QDFMED
      KINJHK

BUTIONS: 52314 KINJHK KINJHKQDFMED
      QDFMED42 KINJHK524 MBCXZ
      56.321 ILOLKI 421

例如,在 EVENTS 部分中,减少了 QDFMED KINJHK QDFMED 行和下面几行之前的空格.但我希望使用 wrap() 方法后对齐不应受到干扰.

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.

谢谢.可见.

推荐答案

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

Which version of the Text::Wrap module are you using? Using 2009.0305 as in

#! /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

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

produces the output you want and does not reduce the indentation.

EVENTS: KINJHK QDFMED QDFMED
        QDFMED KINJHK QDFMED
        KINJHK

BUTIONS: 52314 KINJHK KINJHKQDFMED
         QDFMED42 KINJHK524 MBCXZ
         56.321 ILOLKI 421

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

Note: all whitespace in the code is space characters, no TABs. Replacing spaces with leading TAB characters made no difference in the output, however.

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

Perhaps there is some other important bit of context in your code that we don’t yet know about.

这篇关于Perl:无法按照确切要求使用 Text::Wrap:wrap()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆