【发布时间】:2012-11-07 14:41:34
【问题描述】:
我有一个负责格式化输出的 Perl 代码。问题是我需要计算要在每个字符串中的一个特定字符之前放置的正确标签数(假设它是 /)。因此,我不想得到不同长度的行,而是得到固定长度的字符串(但尽可能短,使用最长的作为最大值)。我应该如何处理这个?
输出示例(格式被注释掉,只是原始数组):
Long title with some looong words / short text Another title / another short text
我需要这样的:
title with some looong words / short text
Different title / another short text
这是我的第一次尝试,但它不涉及在一个特定字符后使用制表符。
my $text = Text::Format->new;
$text->rightAlign(1);
$text->columns(65);
$text->tabstop(4);
$values[$i] = $text->format(@values[$i]);
【问题讨论】:
-
1.迭代所有字符串以找到最大长度 2。将制表符插入其他字符串以匹配先前找到的最大长度 3...? 4. 利润
-
请添加一些示例数据。很难理解你想做什么。
标签: perl text formatting