与 Perl 和 Ruby 比较的相似语言特性 __END__
背景
Perl 和 Ruby 具有 __END__
和 __DATA__
标记,允许将任意数据直接嵌入源代码文件中。
尽管这种做法可能不适合通用编程用途,但对于例行任务的“一次性”快速脚本非常有用。
问题:还有
哪些其他编程语言支持相同或类似的功能,它们是如何实现的?
Background
Perl and Ruby have the __END__
and __DATA__
tokens that allow embedding of arbitrary data directly inside a source code file.
Although this practice may not be well-advised for general-purpose programming use, it is pretty useful for "one-off" quick scripts for routine tasks.
Question:
What other programming languages support this same or similar feature, and how do they do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Fortran 有一个 DATA 语句,听起来就像您正在寻找的那样。
Fortran has a DATA statement that sounds like what you're looking for.
VIC20 和 C64 的基础上有一个“Data”命令,其工作原理如下:
数据可以通过 READ 命令读取。
我不再有 c64 来测试我的代码。
Basic on the VIC20 and C64 had a "Data" command that worked something like this
Data could be read via a READ command.
I no longer have a c64 to test my code on.
SAS具有
datalines
结构,用于在源程序中嵌入外部数据文件,例如在下面的程序中,有5个数据线(终止符是一行中的分号本身)SAS has the
datalines
construct which is used for embedding an external data file inside the source program, e.g. in the following program, there are 5 datalines (the terminator is the semi-colon on a line by itself)Perl 支持 __DATA__ 标记,您可以像访问常规文件句柄一样访问其内容。
Perl supports the
__DATA__
marker, which you can access the contents of as though it were a regular file handle.