Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

My Stupid Head, or why you should never stop thinking

by btrott (Parson)
on Jul 27, 2001 at 09:51 UTC ( #100231=perlmeditation: print w/replies, xml ) Need Help??

It's been said before and before again, but here is another example of why you should never let yourself get locked into a particular way of thinking about a problem.

I'm working on a pure-Perl OpenPGP implementation (will be on CPAN in the next couple of days, Crypt::OpenPGP; the link will work when it's up :). And so on this particular day today I am working on the compression code, using Compress::Zlib.

Decompression worked fine, but I had a problem with compression: every time I would compress a data packet, GnuPG and PGP5 would have strange and mysterious errors when decompressing it. The errors usually didn't prevent the programs from decompressing the data, but they would die ugly deaths soon afterwards.

It turns out that the reason I was having the problem is because I am very, very stupid.

For the compression code I am using the relatively low-level Compress::Zlib interface (deflateInit, etc.) and after deflating, I am calling flush. And I was giving flush the Z_PARTIAL_FLUSH parameter, and then I tried Z_SYNC_FLUSH, etc. etc. The reason I did this is because when I was writing the compression code for Net::SSH::Perl, it took me a while to realize that I needed to use Z_PARTIAL_FLUSH. So I figured, why not save myself some time and just start using the "correct" flush type in the beginning.

This is a problem when the "correct" flush type is not so correct.

So I spent hours debugging the code, printing out hex dumps of the compressed and decompressed data, etc.

All the time not realizing that *the default*, Z_FINISH (which you get if you don't supply any args at all--hence default), is what works for PGP.

  • Comment on My Stupid Head, or why you should never stop thinking

Replies are listed 'Best First'.
Re: My Stupid Head, or why you should never stop thinking
by jepri (Parson) on Jul 27, 2001 at 11:56 UTC
    Funny you should mention that. I just spent a day implementing a LZW compressor in Perl. It took me a long time to do, I suspect because I am qutie thick, but mainly I was trying to do it by looking at C source code.

    Kids, do not try this at home! The C program, which was meant to demonstrate clearly how it all worked was in fact horribly obfu. Linked lists everywhere, and ick. OTOH, it did run about 100 times faster than my Perl effort.

    My little bit of agony was that I wasn't implementing the linked lists quite right. The first few lines were decompresing correctly, but as the program went further random garbage would appear, eventually obscuring the text. I was so close.

    Many hours of shotgun debugging later, I threw out my pseudo-C code, and implemented a Perl version of a mathematical description of the LZW process. I nearly fell off my chair when it compiled and ran perfectly first time. I think that may be a lifetime first too.

    So there is a moral to this story - don't do C, it ruins your style ;P

    I would post the code, but Unisys are very clear that they will not tolerate even free versions to be distributed.

    I didn't believe in evil until I dated it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://100231]
Approved by root
[LanX]: memories....I missed my connection while chatting
[Discipulus]: in this case Corion we are speaking about software licensing: evry year or two we must rescan the whole ced to produce an excel report, while at every activation / disactivation we update a black box DB: i said that i a week i can produce the perl to..
[Discipulus]: rend out the xls IF i have access to the DB
[choroba]: LanX I miss working in a bank sometimes...
[Corion]: Discipulus: Ooof. Especially yearly things are things I like to automate instead of trying to remember how I did things last year...
[Corion]: And the second rule that I've learned is, that there is no one-off job, so writing a program for it pays off almost immediately. The third rule is to give all my programs numbers and have them reproduce that number in the name of their output files. :)
[Discipulus]: the true part is that also specification change between years.. but well our job is cheap but dont abuse of us.. ;=)
[LanX]: Choroba: do you miss chaos with ties? apply at the US government.. ;)

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (15)
As of 2017-03-29 12:07 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (350 votes). Check out past polls.