Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何在perl中跳过自动生成的unicode字符范围中的保留unicode字符?_Regex_Perl_Unicode - Fatal编程技术网

Regex 如何在perl中跳过自动生成的unicode字符范围中的保留unicode字符?

Regex 如何在perl中跳过自动生成的unicode字符范围中的保留unicode字符?,regex,perl,unicode,Regex,Perl,Unicode,我编写了一个perl程序,用perl自动生成一系列unicode字符 #!/bin/perl -w use strict; use open qw/:std :encoding(UTF-8)/; my ($beg, $end, $start, $finish, @chars); print "Enter the beginning Unicode value of your Language's script: "; chomp( $beg = <> ); print "En

我编写了一个perl程序,用perl自动生成一系列unicode字符

#!/bin/perl -w

use strict;
use open qw/:std :encoding(UTF-8)/;

my ($beg, $end, $start, $finish, @chars);

print "Enter the beginning Unicode value of your Language's script: ";
chomp( $beg = <> );

print "Enter the last Unicode value of your Language's script: ";
chomp( $end = <> );

$beg =~ s/U\+(.*)/$1/;
$end =~ s/U\+(.*)/$1/;

$start  = hex($beg);
$finish = hex($end);

@chars = ( $start .. $finish );

foreach (@chars) {

    my $char = chr($_);

    next unless ($char);

    print "$char\n";
}
#/bin/perl-w
严格使用;
使用开放式qw/:std:encoding(UTF-8)/;
我的($beg,$end,$start,$finish,@chars);
打印“输入语言脚本的起始Unicode值:”;
chomp($beg=);
打印“输入语言脚本的最后一个Unicode值:”;
chomp($end=);
$beg=~s/U\+(*)/$1/;
$end=~s/U\+(.*)/$1/;
$start=hex($beg);
$finish=十六进制($end);
@字符=($start..$finish);
foreach(@chars){
my$char=chr($\ux);
其次,除非($char);
打印“$char\n”;
}
使用值
U+0B80
U+0BFF
运行此脚本时,我的输出是:

஀ ஁ ஂ ஃ ஄ அ ஆ இ ஈ உ ஊ ஋ ஌ ஍ எ ஏ ஐ ஑ ஒ ஓ ஔ க ஖ ஗ ஘ ங ச ஛ ஜ ஝ ஞ ட ஠ ஡ ஢ ண த ஥ ஦ ஧ ந ன ப ஫ ஬ ஭ ம ய ர ற ல ள ழ வ ஶ ஷ ஸ ஹ ஺ ஻ ஼ ஽ ா ி ீ ு ூ ௃ ௄ ௅ ெ ே ை ௉ ொ ோ ௌ ் ௎ ௏ ௐ ௑ ௒ ௓ ௔ ௕ ௖ ௗ ௘ ௙ ௚ ௛ ௜ ௝ ௞ ௟ ௠ ௡ ௢ ௣ ௤ ௥ ௦ ௧ ௨ ௩ ௪ ௫ ௬ ௭ ௮ ௯ ௰ ௱ ௲ ௳ ௴ ௵ ௶ ௷ ௸ ௹ ௺ ௻ ௼ ௽ ௾ ௿

所有这些方框字符都是Unicode块中的保留空格

我想删除所有这样的保留空间。有没有办法在perl中实现这一点


除非($char),否则行
似乎不起作用,因为即使是保留空间似乎也有一个值(框字符)。

您似乎需要未分配的类别:

next if $char =~ /\p{Unassigned}/;
# Or shorter:
next if $char =~ /\p{Cn}/;
您也可以使用

输出:

ஂஃ
当您删除下一个
时,它将是:

஀஁ஂஃ

更新:我对中使用的三种技术进行了基准测试,并给出了我的答案
charnames
显然损失惨重

use charnames ();
use open qw/:std :encoding(UTF-8)/;
use Benchmark ':all';

cmpthese(
    '-2',
    {
        'charnames' => sub {
            foreach ( hex 'B80' .. hex 'BFF' ) {
                next unless charnames::viacode($_);
            }
        },
        'posix' => sub {
            foreach ( hex 'B80' .. hex 'BFF' ) {
                next unless ( chr($_) =~ /[[:print:]]/ );
            }
        },
        'unassigned' => sub {
            foreach ( hex 'B80' .. hex 'BFF' ) {
                next if ( chr($_) =~ /\p{Cn}/ );
            }
        },
    }
);

__END__
              Rate  charnames      posix unassigned
charnames   28.4/s         --      -100%      -100%
posix      27115/s     95239%         --       -14%
unassigned 31656/s    111205%        17%         --

您只想打印可见字符。请参阅


我强烈建议不要使用这种技术。基准相当明确。但我会留下它,因为这是一个我不知道的特性,corelist说它从Perl 5.6.0开始就存在了。还要注意,如果基准测试运行多次,posix和unassigned是相当相等的
use charnames ();
use open qw/:std :encoding(UTF-8)/;
use Benchmark ':all';

cmpthese(
    '-2',
    {
        'charnames' => sub {
            foreach ( hex 'B80' .. hex 'BFF' ) {
                next unless charnames::viacode($_);
            }
        },
        'posix' => sub {
            foreach ( hex 'B80' .. hex 'BFF' ) {
                next unless ( chr($_) =~ /[[:print:]]/ );
            }
        },
        'unassigned' => sub {
            foreach ( hex 'B80' .. hex 'BFF' ) {
                next if ( chr($_) =~ /\p{Cn}/ );
            }
        },
    }
);

__END__
              Rate  charnames      posix unassigned
charnames   28.4/s         --      -100%      -100%
posix      27115/s     95239%         --       -14%
unassigned 31656/s    111205%        17%         --
next unless ($char=~/[[:print:]]/);