如何在Perl中创建柱状输出?

如何在Perl中创建柱状输出?,第1张

概述!/usr/bin/env perl use warnings; use strict; my $text = 'hello ' x 30; printf "%-20s : %s\n", 'very important text', $text; 这个脚本的输出看起来更像这样: very important text : hello hello hello hellohel !/usr/bin/env perl

use warnings; use strict; my $text = 'hello ' x 30; printf "%-20s : %s\n",'very important text',$text;

这个脚本的输出看起来更像这样:

very important text      : hello hello hello  hellohello hello hello hello hello hello hello hellohello hello hello hello hello hello hello hello...

但我想要一个像这样的输出:

very important text: hello hello hello hello                     hello hello hello hello                     hello hello hello hello                     ...

我忘了提到:文本应该有一个开放的结尾,因为文本行的右端应该对应于终端的大小.

我怎样才能更改脚本以达到目标?

解决方法 你可以使用 Text::Wrap:

use strict;use Text::Wrap;my $text = "hello " x 30;my $init = ' ' x 20;$Text::Wrap::columns = 80;print wrap ( '',$init,'very important text : ' . $text );
总结

以上是内存溢出为你收集整理的如何在Perl中创建柱状输出?全部内容,希望文章能够帮你解决如何在Perl中创建柱状输出?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/langs/1260406.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存