Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

my first try: japh

by zzspectrez (Hermit)
on Nov 08, 2000 at 21:14 UTC ( [id://40556]=obfuscated: print w/replies, xml ) Need Help??

Be nice, this was hard for me!


#!/usr/bin/perl @d=(255,60,252,195,24,195,195,195,24,255,252,255, 216,195,192,195,112,195,192,195);for($n=1;$n < 21; $n++){$d .= ' ' . unpack("B8",pack("v",shift(@d))); unless ($n % 4){$d =~ s/0/ /g;print "$d\n";$d = '';}}

laterz
zzspectrez

Replies are listed 'Best First'.
RE: my first try: japh
by tedv (Pilgrim) on Nov 08, 2000 at 23:09 UTC
    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

      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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-03-28 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found