Perl:基本问题,功能功能

Le_*_*eur 1 perl heredoc

这个功能有什么作用?

    sub MyDigit {
       return <<END;
       0030\t0039
       END
    }
Run Code Online (Sandbox Code Playgroud)

Eth*_*her 8

这称为"here-document",用于在多行中打破字符串,作为连接或列表操作的替代方法:

print "this is ",
    "one line when printed, ",
    "because print takes multiple ",
    "arguments and prints them all!\n";
print "however, you can also " .
    "concatenate strings together " .
    "and print them all as one string.\n";

print <<DOC;
But if you have a lot of text to print,
you can use a "here document" and create
a literal string that runs until the
delimiter that was declared with <<.
DOC
print "..and now we're back to regular code.\n";
Run Code Online (Sandbox Code Playgroud)

您可以在手册中阅读有关here-documents的更多信息:请参阅perldoc perlop.

  • @Sinan:看我的回答.每个人都错过了这里真正发生的事情! (2认同)

tch*_*ist 7

你们都错过了这一点!

它定义了一个用户定义的属性,用于\p{MyDigit}\P{MyDigit}使用正则表达式.

就像这样:

  sub InKana {
      return <<'END';
  3040    309F
  30A0    30FF
  END
  }
Run Code Online (Sandbox Code Playgroud)

或者,您可以根据现有属性名称定义它:

  sub InKana {
      return <<'END';
  +utf8::InHiragana
  +utf8::InKatakana
  END
  }
Run Code Online (Sandbox Code Playgroud)

您也可以使用"C < - >"前缀设置减法.假设您只想要实际字符,而不仅仅是块字符范围.你可以清除所有未定义的像这样:

  sub IsKana {
      return <<'END';
  +utf8::InHiragana
  +utf8::InKatakana
  -utf8::IsCn
  END
  }  
Run Code Online (Sandbox Code Playgroud)

您还可以使用"C"前缀从补充字符集开始:

  sub IsNotKana {
      return <<'END';
  !utf8::InHiragana
  -utf8::InKatakana
  +utf8::IsCn
  END
  }
Run Code Online (Sandbox Code Playgroud)

我想我一定是对的,因为我说的是前来的.:)