D
David K. Wall
If I want a program to print its own source code, is there any reason
to prefer one of these code snippets over the other? Or is there an
even better way to do it?
The context I'm thinking of is a CGI program that can be used as
working code and also optionally provide a copy of itself to interested
persons. (Obviously I'd have to provide proper HTTP headers....)
Snippet 1:
seek DATA, 0, 0;
print <DATA>;
__DATA__
Snippet 2:
open SELF, $0 or die "Error opening self for reading";
print <SELF>;
to prefer one of these code snippets over the other? Or is there an
even better way to do it?
The context I'm thinking of is a CGI program that can be used as
working code and also optionally provide a copy of itself to interested
persons. (Obviously I'd have to provide proper HTTP headers....)
Snippet 1:
seek DATA, 0, 0;
print <DATA>;
__DATA__
Snippet 2:
open SELF, $0 or die "Error opening self for reading";
print <SELF>;