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 | [reply] [Watch: Dir/Any] [d/l] [select] |
Cool!! Thanks for the help!! I tried using $_but then added some other bug when I did. I was unaware of both @_ and $/, so thank you for my introduction.
When you using the construct for $n (1..@_) is this working like a foreach construct?? $n equals each item in the list i.e. 1..@_??
One minor correction to the code, though.. I tried the moddifications and it didnt work properly unless
pack("v",shift) is changed to
pack("v",shift@_)
As far as using the list nature of pack, Im not sure I would know how to go about it. This was the hardest part for me to figure out. I dont completly understand how to use pack or unpack properly. I orginaly kept pulling my hair out thinking that unpack("B8",shift (@D)) should work. I didnt realize that I need to pack the binary string into actual binary data.
Thanks a lot for the suggestions! zzspectrez
| [reply] [Watch: Dir/Any] [d/l] [select] |