Happy Birthday Perl
Happy 25th Birthday, Perl! I made you a card:
perl -C -e'print map+(v9635 x8^unpack B8).(v10)[++$n%9],(unpack u,"MK__^=^WW_S_WK)FNO\$3F5U\$7BJJ.=>U51S-WK)GNM>UF=W%[K[N>?___SW__")=~/./g'
Happy 25th Birthday, Perl! I made you a card:
perl -C -e'print map+(v9635 x8^unpack B8).(v10)[++$n%9],(unpack u,"MK__^=^WW_S_WK)FNO\$3F5U\$7BJJ.=>U51S-WK)GNM>UF=W%[K[N>?___SW__")=~/./g'
Nice!
Yes, really nice!
can you please explain it?
(I know, it is much asked to explain a gift, but I really don't get it..)
:-)
Wide character in print at -e line 1.
@:m): Ok, here it goes:
The
"MK__^..."string is the uuencoded bitmap. The second call tounpackuudecodes it, returning a string of bytes, each representing 8 "pixels" of the image. The=~/./g partturns it into a list of bytes (you could also do that usingsplit//), which is then passed as the second argument tomap.The first argument to
maphas another call tounpack, which takes each byte and transforms it to a string with its binary representation (e.g."00101101"), with 0s and 1s corresponding to pixels. This string is then XORed (^) with another string of the UTF-8 character\x{9635}(represented with the shorter version string notation,vXXXX) repeated 8 times (x8), which happens to produce lighter and darker blocks for 1s and 0s -- so the result of a single iteration of map is 8 pixels of the image.The
(v10)[++$n%9]part adds a newline character every 9 bytes (in other words, every 72 pixels).(v10)is the newline character dressed up in a 1-element list. The$nvariable is a counter that is incremented with each iteration, and++$n%9returns 0 when its current value is divisible by 9 -- which means that every 9 iterations, the array index will be 0, and the newline character will be returned and concatenated to the produced pixels. All the strings of 8 pixels (plus the occasional newlines) are returned bymapas a list, and are then, finally, printed.@jrw32982: Your terminal needs to support UTF-8.
Very cool, thanks!
Thanks for the explanation. :-)
cool tricks!