问题
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?
回答1:
Perl supports the __DATA__
marker, which you can access the contents of as though it were a regular file handle.
回答2:
Fortran has a DATA statement that sounds like what you're looking for.
回答3:
Basic on the VIC20 and C64 had a "Data" command that worked something like this
100 DATA 1,2,3
110 DATA 4,5,6
Data could be read via a READ command.
I no longer have a c64 to test my code on.
回答4:
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)
data output;
input name $ age;
datalines;
Jim 14
Sarah 11
Hannah 9
Ben 9
Timothy 4
;
run;
来源:https://stackoverflow.com/questions/2059713/similar-language-features-to-compare-with-perl-and-ruby-end