gpt4 book ai didi

Perl,计算字符并在单词末尾中断

转载 作者:行者123 更新时间:2023-12-01 00:02:55 25 4
gpt4 key购买 nike

我试图在 300 个字符处打断,效果很好,但我不希望它在单词中间打断。我想找到一个词的结尾或下一个可用的空格。任何帮助将不胜感激。

foreach (@$comp) {
my $c = $_;
$c->{reviews} = ($c->{reviews} - 1);
my $stars;
if($c->{reviews} == 0) {
$stars = 0;
} else {
$stars = int($c->{reviews_total} / $c->{reviews});
}
$c->{stars} = $stars;

if($c->{title}) {
$c->{name} = $c->{title};
$c->{event} = "FOO";
}
$c->{description} =~ s/BREAK//g;

my (@desc) = split(//, $c->{description});

my $adesc;
my $rowc = 0;
my $count = 0;

while($count < 300 ) {
$adesc .= @desc[$count];
$rowc++;
$count++;
}

$c->{description} = $adesc;= '...';
}

最佳答案

让我们看看是什么perldoc perlfaq4不得不说:

How do I reformat a paragraph?

Use Text::Wrap (part of the standard Perl distribution):

use Text::Wrap;
print wrap("\t", ' ', @paragraphs);

The paragraphs you give to Text::Wrap should not contain embedded newlines. Text::Wrap doesn't justify the lines (flush-right).


如果你不喜欢怎么办?

访问CPAN

关于Perl,计算字符并在单词末尾中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8928331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com