79360685

Date: 2025-01-16 07:30:53
Score: 1
Natty:
Report link

Use my Text::VisualPrintf or Text::ANSI::Printf.

Text width can be taken by Text::VisualWidth::PP::vwidth.

use Encode qw/decode encode/;
use Text::VisualPrintf qw/vprintf vsprintf/;
use Text::VisualWidth::PP qw/vwidth/;
use Text::CharWidth qw/mbswidth/;
use utf8;

$\ = "\n"; $, = "\t";

my @in = map { chomp; $_ } <>;

my @l = map {
    my $decoded = utf8::is_utf8($input) ? $input : decode("UTF-8", $_);
    [
     vsprintf ("%-32s", $decoded),
     sprintf ("%02i", vwidth($decoded)),
     sprintf ("%02i", mbswidth($decoded)),
     sprintf ("%02i", length($decoded)),
     sprintf ("%02i", length($_)),
    ]
} @in;

print encode "UTF-8", $_ for map { join " | ", $_->@* } @l;

output

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Kaz Utashiro