Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Interns are NOT lazy!

by Cirollo (Friar)
on Aug 16, 2001 at 19:57 UTC ( #105418=obfuscated: print w/replies, xml ) Need Help??

My first obfuscation (other than my summer projects, bwahaha), this code is an end-of-summer-internship tribute to my employer, Texas Instruments. I love having a job where I can play with Perl :) Runs with strict, but sorry, no -w. Tested with 5.6 and 5.004 on Solaris and 5.6 on NT.
#!/usr/bin/perl undef $/;$\= $:;$\=~s/-// ; $_ =<DATA> ;chomp;s/\s+ //gx;map{$a=$2;{$a.=/^[<`~]/x?/\w/x &&($`eq'<'?'*':$`eq'~'?"\124": $`eq '`'?'I':0)x hex$&:/^[^TI*]/x?$"x hex $&:/./? substr ($_,0,1):0;$_=$';$_ ne $,? redo:last ;}print $a;}(split(/\|/)) __DATA__ B<C|B*A*B`3|B*A*AI2I|B*A*A`3|B*A<6T9T<7|B*FT2`5 2T7*|B*9~62I3I2~63*|B*8T7I3I7T4*|<C7~62 I3I2~66*|1*F6T2I3I2TD*|2*F4T2`5 2TE*|5<2 8**4T9TE*|8*4*4 *1~BD* |A<28*F5*|F7 *E*|F9*9*|FB *6*|FC*4*| FD*3*| FE**

Replies are listed 'Best First'.
Re: Interns are NOT lazy!
by E-Bitch (Pilgrim) on Aug 17, 2001 at 02:50 UTC
    I Love being an intern... lets see if I have some mojo today....

    first, break it apart on the semicolons and {}:
    undef $/; $\=$:; $\=~s/-//; $_ =<DATA>; chomp; s/\s+//gx; map { $a=$2; { $a.=/^[<`~]/x?/\w/x &&($`eq'<'?'*':$`eq'~'?"\124": $`eq '`'?'I':0) +x hex$&:/^[^TI*]/x?$"x hex $&:/./? substr ($_,0,1):0;$_=$'; $_ ne $,? redo:last ; } print $a; } ( split(/\|/)) __DATA__ B<C|B*A*B`3|B*A*AI2I|B*A*A`3|B*A<6T9T<7|B*FT2`5 2T7*|B*9~62I3I2~63*|B*8T7I3I7T4*|<C7~62 I3I2~66*|1*F6T2I3I2TD*|2*F4T2`5 2TE*|5<2 8**4T9TE*|8*4*4 *1~BD* |A<28*F5*|F7 *E*|F9*9*|FB *6*|FC*4*| FD*3*| FE**

    well, I guess that some interns are smarter than others, and I have no mojo today. :) my apologies for filling up the replies with gibberish. The part that really hung me out was that bit after __DATA__, with the pipes. (to other monks:) what is that doing?

    Update: WAIIIIT!!!! I just stepped back from it... pure genius... okay, so lemme get this straight... __DATA__ is being read in using the same syntax as <STDIN>??? OKay, that is cool... and then, the data is being shot through that loop?

    Okay... so continuing then: first, you undefined the record separator ($/), then you redefined it to the line break character ($/ = $:;), then, redefined it again to a regexp matching the whole line(?) to replace all those dashes with nothing(?) (so, i'm assuming the first time you did it was for visual effect, aka space filling?),

    Then, you read a line of data from __DATA__ <Still in awe that that works>
    then, chomp the line, and use a regexp on it... lesse what that regexp does...

    so, you treat the entire line as a record for the regexp, and match any number of whitespace characters, looping through the regexp and replacing said whitespace characters with nothing...

    from there, call the map function, with the long regexp as the first argument, and the split as the list of characters to apply the map to.

    from there, print it out to the screen.

    I know i probably missed something, but this is my first ever shot at doing this..

    Update again: Thanks jynx... dont know how I missed the difference between / and \. musta been goin too fast eh? thanks!

    Tempora Mutantur Nos et Mutamur in Illis
    "The Times are Changed Even as We are Changed in Them"


      Some minor corrections:

      The first time he did
         undef $/;
      so that he could read in all of <DATA> at once, and then he set
      (note the different lean of the second character) which is the output record seperator so that his output is formatted properly. As a note, he sets it to " \n-" (the format line break variable) and then removes the hyphen, so his output record seperator is now a space followed by a "\n". Very convenient ;)

      He formats $_ to have no line breaks or white space, then the map takes care of using the DATA as logic for how to visually represent the material. Since it's a map, when he prints $a it'll get treated as part of an array, which is useful for putting in the "\n" without being seen (from the output record seperator). Finding out the logic of the DATA section is left as an exercise for the reader.

      Hope That Helps,

      update: reworded a few lines...

(ichimunki) Re: Interns are NOT lazy!
by ichimunki (Priest) on Aug 17, 2001 at 02:52 UTC
    I was kind of hoping this would spit out a Texas flag captioned "Don't Mess With Texas", but the way it is makes a much nicer tribute to TI. :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://105418]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2016-09-01 03:35 GMT
Find Nodes?
    Voting Booth?
    The best thing I ever won in a lottery was:

    Results (439 votes). Check out past polls.