http://www.perlmonks.org?node_id=40600


in reply to my first try: japh

You might want to try using "special" variables to make your life easier and/or more obfuscated. For example, don't use @d. Use @_ instead. This means you can write shift instead of shift(@d). You can use $/, the newline separator, instead of \n. Similar to @_, you could use $_ instead of $d which gets you tighter regular expressions. And lastly, instead of making your for loop work like C code (for ($n=1;$n < 21; $n++)), you might try something like for $n (1..@_). Note that @_ is forced into scalar context, which translates to the length, which is 20.

Here is what your code might turn into after these changes:
#!/usr/bin/perl @_=(255,60,252,195,24,195,195,195,24,255,252,255, 216,195,192,195,112,195,192,195);for $n(1..@_){ $_ .=' '.unpack("B8",pack("v",shift));unless($n%4) {s/0/ /g;print $_,$/;$_='';}}

Other thoughts include using the list nature of pack to simplify the for loop. Also, the numbers 255, 195, and 192 come up multiple times in the data block. You might want to start with a smaller data block and graft multiple copies of those numbers into it. It might result in smaller code.

-Ted