In Perl6::Form
, is it possible to wrap text at any character not just spaces?
| Item |
| {[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[} |
@phrase,
Above formatting generates,
| Item |
| Word1 |
| Super_________long________________word1 |
I want it to break the word itself. Is it possible to do that? Like below
| Item |
| Word1 Super_________long_______________ |
| _word1 |
Also, in this example. Why isn't blah2 or 1.3 or 101.0
not aligned with with its corresponding values of the table 12
my @name=();
my @score=();
my @time=();
my @normalized=();
push(@name,'blah1');
push(@score,'115555555');
push(@time,1.1);
push(@normalized,100);
push(@name,'blah2');
push(@score,'12');
push(@time,1.3);
push(@normalized,101);
print form
'-------------------------------------------',
'Name Score Time | Normalized',
'-------------------------------------------',
'{[[[[[[[[[[[[} {[[[} {II} | {]]].[[} ',
\@name, \@score,\@time, \@normalized;
-------------------------------------------
Name Score Time | Normalized
-------------------------------------------
blah1 1155- 1.1 | 100.0
blah2 55555 1.3 | 101.0
12 |
From documentation, I learned I can use layout and break options to accomplish the behavior I was looking for
print form
{layout=>"tabular"},
{break=>\&break_width},
But the function posted in the doc has compile issues:
sub break_width {
my ($data_ref, $width, $ws) = @_;
for ($$data_ref) {
# Treat any squeezed or vertical whitespace as a single character
# (since they'll subsequently be squeezed to a single space)
my $single_char = qr{ $ws | [\n\r]+ | . }
# Give up if there are no more characters to grab...
return ("", 0) unless m/\G (single_char{1,$width}) /gcx;
# Squeeze the resultant substring...
(my $result = $1) =~ s/ $ws | [\n\r] / /gx;
# Check for any more data still to come...
my $more = m/\G (?= .* \S) /gcx;
# Return the squeezed substring and the "more" indicator...
return ($result, $more);
}
}
After fixing basic issues with this function, I am still hitting uninitialized $ws
. Clearly this is not tested code. Am I missing something?