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
Javascript 使用Perl将斜体字发布到twitter_Javascript_Perl_Twitter_Unicode - Fatal编程技术网

Javascript 使用Perl将斜体字发布到twitter

Javascript 使用Perl将斜体字发布到twitter,javascript,perl,twitter,unicode,Javascript,Perl,Twitter,Unicode,我正在使用Net::Twitter::Lite,我想用斜体字发布包含部分的文本。我了解到这在Unicode中是可能的:有Java脚本代码,但我不理解它。是否有一些Perl代码也能做到这一点?或者有人可以解释一下JavaScript的功能,这样我就可以在Perl中使用JavaScript了。这个程序将把字符串转换成斜体,使用Unicode字符作为数学符号 #!/usr/bin/perl -CS use strict; use warnings; use 5.010; use charnames

我正在使用Net::Twitter::Lite,我想用斜体字发布包含部分的文本。我了解到这在Unicode中是可能的:有Java脚本代码,但我不理解它。是否有一些Perl代码也能做到这一点?或者有人可以解释一下JavaScript的功能,这样我就可以在Perl中使用JavaScript了。

这个程序将把字符串转换成斜体,使用Unicode字符作为数学符号

#!/usr/bin/perl -CS

use strict;
use warnings;
use 5.010;

use charnames ':full';

my $out;
foreach (@ARGV) {
  foreach my $char (split //) {
    if ($char =~ /[A-Z]/) {
      my $charname = "MATHEMATICAL ITALIC CAPITAL $char";
      $char = charnames::string_vianame $charname;
    } elsif ($char =~ /[a-z]/) {
      my $charname = 'MATHEMATICAL ITALIC SMALL ' . uc $char;
      $char = charnames::string_vianame $charname;
    }
    $out .= $char;
  }
}
say $out;

如果您有旧版本的Perl,则可以使用以下内容:

#!/usr/bin/perl

binmode(STDOUT, ":utf8");

$output="";
foreach (@ARGV)
{
 foreach $char (split //)
 {
  if ($char =~ /[A-Z]/) {$d=119860-65+ord($char); $char = pack("U",$d)}
  if ($char =~ /h/) {$char="\x{210e}"}
  if ($char =~ /[a-z]/) {$d=119886-97+ord($char); $char = pack("U",$d)}
  $output .= $char;
 }
}

print "$output\n";

谢谢我的Perl抱怨:无法通过utf-italics.pl第17行的包charnames找到对象方法string_vianame。看起来该函数是在Perl 5.14中添加的。看,我现在有了一个可以工作的Perl并得到了斜体,然而,我的Perl5.16似乎不喜欢h:它说:在串联中使用未初始化的值$char。或者utf-test.pl第19行的字符串。显然“数学斜体小H”不存在,因为它与“普朗克常数”是同一字形。因此,您需要为此编写一个特例,或者您可以添加一个别名:use charnames:alias=>{mathematic ITALIC SMALL H=>PLANCK CONSTANT};