如何在Perl中创建柱状输出?
发布时间:2020-12-16 06:28:41 所属栏目:大数据 来源:网络整理
导读:!/usr/bin/env perl use warnings; use strict; my $text = 'hello ' x 30; printf "%-20s : %sn",'very important text',$text; 这个脚本的输出看起来更像这样: very important text : hello hello hello hellohello hello hello hello hello hello hell
!/usr/bin/env perl
use warnings; use strict; my $text = 'hello ' x 30; printf "%-20s : %sn",'very important text',$text; 这个脚本的输出看起来更像这样: very important text : hello hello hello hello hello hello hello hello hello hello hello hello hello 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 ); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |