Note to self about class methods

Don't use them unless you are knowing what you are doing. I recently ran into something strange and was quite busy fixing the problem using much database mojo.

For the calculation of some MD5 sums I was using Digest::MD5. And for some reason I used it this way:

  1. perl -MDigest::MD5 -le 'print Digest::MD5->md5_hex("foo")'
  2. 3200a4cda22a4a935412da8113b4139b

Looks good doesn't it? But the MD5 digest is incorrect. Just try it yourself and enter 'foo' in any given web MD5 generator out there.

The right way to use Digest::MD5 (and Digest::SHA1 too) would be

  1. perl -M'Digest::MD5 "md5_hex"' -le 'print md5_hex("foo")'
  2. acbd18db4cc2f85cedef654fccc4a4d8

Okay, my fault. But this annoys me a bit:

  1. perl -w -MDigest::MD5 -le 'print Digest::MD5->md5_hex("foo")'
  2. &Digest::MD5::md5_hex function probably called as class method at -e line 1.
  3. 3200a4cda22a4a935412da8113b4139b
  4. fh$ perl -Mstrict -Mwarnings -MDigest::MD5 -le \
  5. 'print Digest::MD5->md5_hex("foo")'
  6. 3200a4cda22a4a935412da8113b4139b

To be honest I have no idea, why -w produces a warning (which is a good thing) and use warning doesn't.