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. How to compile Perl
    By tech291083 in forum Redhat / Fedora
    Replies: 3
    Last Post: 06-09-2007, 01:46 PM
  2. Perl module problem
    By Outlaw in forum Linux - Software, Applications & Programming
    Replies: 3
    Last Post: 05-04-2005, 02:17 PM
  3. PHP & Perl??
    By SwampDonkey in forum Linux - Software, Applications & Programming
    Replies: 8
    Last Post: 07-25-2004, 04:12 PM
  4. PERL Problems
    By marce_sadico in forum Redhat / Fedora
    Replies: 0
    Last Post: 08-26-2002, 05:23 PM
  5. Perl escaping - help needed
    By andrzej in forum Linux - Software, Applications & Programming
    Replies: 6
    Last Post: 05-10-2002, 01:21 PM

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
  •