Hmm, truly fascinating stuff. For those that are interested here is an explanation and some code snippets

#!/usr/bin/perl print <DATA>; print "\n----\n"; seek(DATA,0,0); print <DATA>; __END__ 1 2 3

When you run this you see two interesting things:

1 2 3 ---- #!/usr/bin/perl print <DATA>; print "\n----\n"; seek(DATA,0,0); print <DATA>; __END__ 1 2 3
First the data after the __END__ tag is read and printed. I used to think you had to use __DATA__ Evidently not. Next the SEEK resets the pointer not to the begining of the special file handle __END__ but to the begining of the file! Personally I would call this a *bug* but one mans bug is another man's feature.

Next consider this code

#!/usr/bin/perl seek(DATA,0,0); print map{$. . $_}<DATA>; __END__

This prints:

5#!/usr/bin/perl 5 5seek(DATA,0,0); 5print map{$. . $_}<DATA>; 5__END__

So within the map $. (the line number special var) is always 5 (the total lines)

Now consider this:

#!/usr/bin/perl -w seek(DATA,0,0); *a=*.; print map{$a-=1;$..$_}<DATA>; __END__

This prints:

C:\>perl test4.pl 5#!/usr/bin/perl -w 4 3seek(DATA,0,0); 2*a=*.; 1print map{$a-=1; $. . $_}<DATA>; 0__END__

Ahha so the glob assignment *a=*. does several things. Initially in the map $a is set to $. so $a=5. We then decrement $a which changes $.

Finally consider this:

#!/usr/bin/perl -w use strict; #Just #Another #Perl #Hacker seek(DATA,0,0); *a=*.; print map{$a-=chomp;s/.//; "$.\t$_\n" }<DATA>; __END__

This prints:

12 !/usr/bin/perl -w 11 10 se strict; 9 8 Just 7 Another 6 Perl 5 Hacker 4 3 eek(DATA,0,0); 2 a=*.; 1 rint map{$a-=chomp;s/.//; "$.\t$_\n" }<DATA>; 0 _END__

So now we can do a deconstruct:

#!/usr/bin/perl -w use strict; #Just # our data #Another #Perl #Hacker seek(DATA,0,0); # seek the begining of the file *a=*.; # glob assignment warn # same effect as print but includes the line num map{ $a-=chomp # chomp return num chars chomped (1) thus $a -= 1 , # comma op could be ; without changing result s # substitute <.> # first char on line ;q<''>; # with an expression that evals to null eieio # the /ee makes second part eval to null # the /i (ignore case) does not matter. # and the /o compiles once # put them together and you have: # Old Macdonald Had A JAPH E I E I O ; # yeah well if you need this explained.... $.<8&&$.>2?"$_ ":''# this is ($. < 8 and $. > 2) ? "$_ " : "", # we actually only need lines 5-8 (see above) } # close map <DATA>; # map data array (whole file) __END__


cheers

tachyon


In reply to Re: Seekers of Perl Obfuscation by tachyon
in thread Seekers of Perl Obfuscation by chromatic

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.