Over on rec.puzzles on Usenet (<[EMAIL PROTECTED]>), somebody
posted a puzzle asking about using programming languages to print out a
program's own source code. So, I quickly whipped up the following 11-line
script in Perl:
<snip>
#! perl -w
use strict;
my $selfprint="c:/scripts/selfprint.pl";
open SELFPRINT, "$selfprint" or die "Cannot open $selfprint for read :$!";
while (<SELFPRINT>) {
print;
}
</snip>
I opened up the DOS prompt in Windows 98, and ran the script. The result
was the following:
<snip>
Microsoft(R) Windows 98
(C)Copyright Microsoft Corp 1981-1999.
C:\WINDOWS>cd\scripts
C:\scripts>perl selfprint.pl
#! perl -w
use strict;
my $selfprint="c:/scripts/selfprint.pl";
open SELFPRINT, "$selfprint" or die "Cannot open $selfprint for read :$!";
while (<SELFPRINT>) {
print;
}
C:\scripts>
</snip>
Two questions:
1) When the script prints itself out, it prints an extra blank line before
giving me the command line again. (I've got the script open in my text
editor, set to show line numbers, and there are definitely only 11
lines.) Where's the blank line coming from?
2) Is it really a good idea for a script to be allowed to open itself? I
don't know if I want to try having a script open itself for write, even if
only to see what would happen. :-)
--
Ted Schuerzinger, [EMAIL PROTECTED]
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs