Results 1 to 3 of 3

Thread: PERL: MD5 Weirdness

  1. #1

    PERL: MD5 Weirdness

    I'm trying to compare 2 MD5 hex digests but I can't seem to get it to work right. Here is the sub that is doing the checking ...

    Code:
    use Digest::MD5;
    
    ....
    
    sub checkmd5($$) {
    my ($package, $saidmd5) = @_;
    
    open(FILE, $package) 
    or die "Can't open $package for reading";
    binmode(FILE);
    
    $pkgmd5 = Digest::MD5->new->addfile(*FILE)->hexdigest;
    
    close(FILE);
    
    if($pkgmd5 == $saidmd5) {
    return 1;
    } else { return 0; }
    
    
    }
    I've tested it by giving it a package with a MD5Sum of a4703d36ada98b2cf4f007831c345e71 and sending a82d3d36ada98b2cf4f007831c345e71 as the $saidmd5. Basically, they are being tested against eachother and should return 1 if they are the same and 0 if not. I currently get 1 when testing the two above. What did I do wrong?

  2. #2

    Re:PERL: MD5 Weirdness

    Code:
       if($pkgmd5 == $saidmd5) {
          return 1;
       } else { return 0; }
    $pkgmd5 is a string, because it has a-f not just 0-9. == isn't for strings. try:

    Code:
    return $pkgmd5 eq $saidmd5;
    (also the if/else is redundant, just return the comparison)

  3. #3

    Re:PERL: MD5 Weirdness

    doh, it's eq! I knew I forgot something! Thanks!

Similar Threads

  1. mouse weirdness - input overload?
    By ph34r in forum Linux - Hardware, Networking & Security
    Replies: 3
    Last Post: 01-09-2005, 07:02 PM
  2. Perl and XML
    By coltrane in forum Linux - Software, Applications & Programming
    Replies: 5
    Last Post: 12-09-2004, 10:57 PM
  3. Hall of Technical Documentation Weirdness
    By trickster in forum General Chat
    Replies: 2
    Last Post: 08-18-2004, 05:02 AM
  4. perl question from a perl newb
    By tolstoy in forum Linux - Software, Applications & Programming
    Replies: 4
    Last Post: 09-06-2002, 01:16 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •