Is there a module that prints a list like `ls -C`?

↘锁芯ラ 提交于 2019-12-13 02:18:30

问题


Is there a module that prints (or helps me printing) a list whose elements are strings (scalars) in a ls -C fashion?

Something like the following imaginary program:

use strict; use warnings;

use Unknown::Module;

my $ls = new Unknown::Module (columns => 3);

$ls -> print_ls_C qw(abc def ghi jklmnop q rst uv wxy z);

The output should then be something like

 abc  jklmnop  uv
 def  q        wxy
 ghi  rst      z

回答1:


use Perl6::Form;
my $cols = shift || 3;
my @list = qw(abc def ghi jklmnop q rst uv wxy z);
print form   q/ {:[{*}[:} / x $cols, ( \@list ) x $cols ;;;
__END__
abc                      jklmnop                  uv
def                      q                        wxy
ghi                      rst                      z

This is from example demo_columns , see more examples in https://metacpan.org/source/DCONWAY/Perl6-Form-0.04/demo



来源:https://stackoverflow.com/questions/24773514/is-there-a-module-that-prints-a-list-like-ls-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!