$print_length
幅の印刷列に収まるように、この中国語のテキストを切り取る短い方法はありますか?
#!/usr/bin/env perl
use warnings;
use 5.10.1;
use utf8;
binmode STDOUT, ':utf8';
use Unicode::GCString;
my $print_length = 15;
my $string1 = 'abcdefghijklmnopqrstuvwxyz';
say substr( $string1, 0, $print_length );
my $string2 = '大佛頂如來密因修證了義諸菩薩萬行首楞嚴經'; # don't know what that means
say fit_for_column( $string2 );
sub fit_for_column {
my ( $string ) = @_;
my $gcs = Unicode::GCString->new( $string );
my $pcw = $gcs->columns();
while ( $pcw > $print_length ) {
$string =~ s/\X\z//;
$gcs = Unicode::GCString->new( $string );
$pcw = $gcs->columns();
}
return $string;
}