Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Code eating code

by jdalbec (Deacon)
on Mar 29, 2005 at 04:22 UTC ( #443029=note: print w/ replies, xml ) Need Help??


in reply to Code eating code

Actually I thought STDOUT of here was quite challenging and educational. Perhaps I made my analysis a bit too tidy. Some of the insights I had into your program were things I really hadn't considered before.

In particular, I was surprised to learn about END blocks executing in reverse order, and I didn't really have a clear idea of how Perl interprets barewords since I usually avoid them. I also didn't realize until after I had posted my analysis that what I referred to as "empty BEGIN; and END; statements" were in fact redeclarations of sub BEGIN and sub END and that's why they didn't show up in the perl -MO=Deparse output.

I'm afraid I have to disagree with you on Code eating code. Your Perl::Tidy suggestion was kind of a tip-off about what you're doing. Tidying does break the code, but...

the tidied version can be fixed as below so that it reads the original source file instead of the tidied source file.

I'm using a C++-style << "operator" to indicate what each line prints.
#!/usr/bin/perl open( eval STDIN, do { (local $_ = $0) =~ s/\.tdy$//; $_ } ); $= = @ARGV = <>; # 16 lines @h = split //, shift; # "#!/usr/bin/perl\n" $- = @ARGV; # 15 lines { local $" = 't'; ( $b = "@{[@h[3,4]]}" ) =~ y~st~ts~; # "ust" } $h = ucfirst join '', @h[ -5 .. -2 ], $"; # "Perl " &39; # "JHV\x9c\x9a\x99V\x89\x90\x95V\x97\x8c\x99\x931" $b = $h[0] . $b . $"; # "Just " print $b; # << "Just " @h = split //, shift; # "open(eval STDIN,\$0);\$==\@ARGV=<> ;\@\n" # 0123456789012345 6789 012 3456789012 3 4 @_ = map { lc } @h[ $= - 3**2, # 16 - 9 == 7 -> a $= % ( $- / 3 ) + 2, # 16 % 5 + 2 == 3 -> n 2**4 - $=, # 16 - 16 == 0 -> o ( 1 x 2 ) x 2, # 11 x 2 -> tt 2, @h - 10, 3**( @h % 3 ) # 2 -> e, -10 -> r, 3 ** (35 % 3) == 9 -> +" " ]; print @_[ 0 .. 3 ], 'h', @_[ 5 .. @ARGV / 2 ], $h, h; # << "another Pe +rl h" $h =~ s/^.//; # "erl " $h =~ s/...$//; # "e" @h = @h[ 0 .. ( ( ( length $ARGV[6] ) - 5 ) / 2 ) ]; # "open(eval STDI +N," &{-14} && print $h[0]; # "abW`\x1aWhS^\x12EF6;\@\x1e" << "a" &14; # "open(eval STDIN," print map lc, @h[ &1 + 6, 6 * 2 + &1 ]; # "qrgp*gxcn\"UVFKP." << "ck" # 012345678 9012345 # ^ ^ print $h, $h[1]; # << "er" print @h[ &{-2} + 1 ]; # "open(eval STDIN," << "," $ARGV[0]; # no-op sub AUTOLOAD { ( ( $a = $AUTOLOAD ) ) =~ s s.*::sss; # extract subroutine name, e.g. "39" for "&39;" $_ = chr( $a + ord $_ ) for @h; # add name as a number to @h $a; # return name, e.g. "39" }


Comment on Re: Code eating code
Select or Download Code
Re^2: Code eating code
by cog (Parson) on Mar 29, 2005 at 11:50 UTC
    Your Perl::Tidy suggestion was kind of a tip-off about what you're doing.

    That was on purpose. Given that the first line of code started with open(eval STDIN,$0);, I figured that there was no point hiding what was going on :-)

    Anyway, only after I posted it did I realize it would only take a copy of the original file and a substitution of $0 by the copy name in order for it to still work :-) duh! :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://443029]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2014-09-17 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (100 votes), past polls