perl - perl 中的 <DATA> 语法

标签 perl

我在哪里可以找到有关 perl 中以下语法的更多信息?
<DATA>之间的联系和 __DATA__不清楚。

while (my $date_string = <DATA>) {
  chomp($date_string);
  next if not length $date_string;
  print "$date_string ist Unixtime ",
        $lang_date->str2time($date_string),
        " und ",
    $lang_date->time2str( '%d.%m.%Y %T (%Z)',$lang_date->str2time($date_string) ),
        "\n";
}

__DATA__
1.3.1999
1 Marz 1999
1. Marz 1999
1/3/1999

最佳答案

报价the doc :

The __DATA__ token tells the perl compiler that the perl code for compilation is finished.

Everything after the __DATA__ token is available for reading via the filehandle FOOBAR::DATA, where FOOBAR is the name of the current package when the __DATA__ token is reached.

This works just the same as __END__ does in package 'main', but for other modules data after __END__ is not automatically retrievable, whereas data after __DATA__ is.



只能添加到使用 __DATA__部分非常方便地说明 Perl 中一些与文件读取相关的概念。它基本上是一个附加到代码的文件,并且可以通过 <DATA> 轻松访问该文件的内容。 .这就是为什么它在 SO 上很受欢迎的原因。 )

关于perl - perl 中的 <DATA> 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13463509/

相关文章:

perl - 如果在没有换行符的情况下写入标准输出,则测试失败

regex - 如何构建正则表达式来解析逗号分隔值但忽略双引号中的逗号?

html - Perl WWW Mechanize submit_form() 未指向请求的 form_number 如何解决?

regex - 如何匹配后跟空格和另一个管道的管道字符?

perl - Perl脚本无法读取其他目录中的文件

regex - Perl 多行正则表达式语句

perl - 通过 perl Mechanize 获取有关文件附件的信息

perl - 如何获得对Perl的grep返回的列表的引用?

database - 在 Perl 中外部存储散列数据

bash - 如何随机查找并替换 BASH 文件中仅出现的一个匹配项?