我正在编写一个Perl程序,将我的本地语言ASCII字符转换为Unicode字符(泰米尔语).
这是我的计划
#!/bin/perl
use strict;
use warnings;
use open ':std';
use open ':encoding(UTF-8)';
use Encode qw( encode decode );
use Data::Dump qw(dump);
use Getopt::Long qw(GetOptions);
Getopt::Long::Configure qw(gnu_getopt);
my $font;
my %map;
GetOptions(
'font|f=s' => \$font,
'help|h' => \&usage,
) or die "Try $0 -h for help";
print "Do you want to map $font? (y/n)";
chomp( my $answer = lc <STDIN> );
$font = lc( $font );
$font =~ s/ /_/;
$font =~ s/(.*?)\.ttf/$1/;
if ( $answer eq "y" ) { …Run Code Online (Sandbox Code Playgroud) 我编写了一个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";
}
Run Code Online (Sandbox Code Playgroud)
在使用值运行此脚本时 …
在搜索某些内容时,我在这里遇到了这个答案.
我想知道为什么变量$first_line只包含输入文件的第一行.
代码:
#!/usr/bin/env perl
use strict;
my $filename = shift;
open my $in_fh, '<', $filename
or die "Cannot open $filename for reading: $!";
my $first_line = <$in_fh>;
open my $out_fh, '>', "$filename.tmp"
or die "Cannot open $filename.tmp for writing: $!";
$first_line =~ s/some translation/goes here/;
print {$out_fh} $first_line;
print {$out_fh} $_ while <$in_fh>; # sysread/syswrite is probably better
close $in_fh;
close $out_fh;
# overwrite original with modified copy
rename "$filename.tmp", $filename
or warn "Failed to …Run Code Online (Sandbox Code Playgroud) 运行以下内容时出错:
perl -ne 'print unless (/[A-G][\d|\s|m|#|$]/)' file
Run Code Online (Sandbox Code Playgroud)
错误:
Unmatched [ in regex; marked by <-- HERE in m/[A-G][ <-- HERE \d|\s|m|#|5.022001/ at -e line 1, <> line 1
Run Code Online (Sandbox Code Playgroud)
我通过逃避]行的末尾解决了错误:
perl -ne 'print unless (/[A-G][\d|\s|m|#|$\]/)' file
Run Code Online (Sandbox Code Playgroud)
为什么我要逃避最后一次]?什么阻止支架匹配?
我注意到所有[]比赛都不是这种情况.这是一个特例吗?