问题
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