in reply to Obfuscation: program seeing own source

Mess around with this a bit:
seek(DATA,0,0); print while(<DATA>); __DATA__
Fun stuff ;)

Jeff

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)

Replies are listed 'Best First'.
Re: Re: Obfuscation: program seeing own source
by andye (Curate) on Feb 08, 2001 at 15:42 UTC
    Excellent!

    But why does seek(DATA,0,0); go to the start of the file, not the start of __DATA__ ?

    andy.

    update: so it's a handle for the script itself... on disk, presumably, rather than in memory? shame.

    #!/usr/bin/perl -w use strict; print "foo\n"; seek(DATA,0,0); while (<DATA>) { s/foo/bar/ and ! /eval/ and eval ; } __DATA__
    versus
    #!/usr/bin/perl -w use strict; print "foo\n"; seek(DATA,0,0); my @me = <DATA> ; foreach (@me) { s/foo/bar/ and ! /eval/ and eval ; } foreach (@me) { s/bar/baz/ and ! /eval/ and eval ; } __DATA__