<DATA>perl 中的语法 [英] The <DATA> syntax in perl

查看:58
本文介绍了<DATA>perl 中的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里可以找到有关 perl 中以下语法的更多信息?

Where can I find more about the following syntax in perl?

__DATA__ 之间的联系尚不清楚.

The connection between <DATA> and __DATA__ is unclear.

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

推荐答案

引用 文档:

__DATA__ 标记告诉 perl 编译器编译完成.

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

__DATA__ 标记之后的所有内容是可通过文件句柄 FOOBAR::DATA 读取,其中 FOOBAR 是到达 __DATA__ 标记时当前包的名称.

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.

这与 __END__ 在包 'main' 中的作用相同,但对于__END__ 之后的其他模块数据无法自动检索,而 __DATA__ 之后的数据是.

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 中一些与文件读取相关的概念.它基本上是一个附加到代码的文件,并且可以通过 轻松访问该文件的内容.这就是为什么它在 SO 上很受欢迎的原因.)

Can add to this only that using __DATA__ section is quite handy to illustrate some file reading-related concepts in Perl. it's basically a file attached to a code, and contents of this file are easily accessible through <DATA>. That's why it's quite popular here on SO. )

这篇关于&lt;DATA&gt;perl 中的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆