Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Why the same hex digest?

by Madams (Monk)
on Mar 16, 2001 at 05:37 UTC ( #64857=perlquestion: print w/ replies, xml ) Need Help??
Madams has asked for the wisdom of the Perl Monks concerning the following question:

Here's the code:
in_some_sub{ open(THISFILE,'< $file') or warn "ERROR: Can't open $outfile!\n"; binmode(THISFILE); while(read(THISFILE,$part,1)){ $md5->add($part); } $data = $md5->hexdigest; return unless ($data); remove_dupes($data,$file); }
(assume a "my ($md5)=new Digest::MD5" earlier and $file is the name returned by "File::Find::name"..)
I've tried using $md5->addfile(*THISFILE), tried using a FileHandle object using $md5->add($part) and $md5->addfile($fh)...

I'm using a hash to keep track of the digests and original file..remove_dupes() notifies of duplicate digests indicating duplicate files and allows you to choose to delete one of them...this code always reports the same:
Fingerprinting files with MD5SUM... Press enter to continue... ERROR: Can't open md5sums.txt! d41d8cd98f00b204e9800998ecf8427e ./Thumbs.db ERROR: Can't open md5sums.txt! ---Duplicates found--- Remove which file: 1."./Thumbs.db" , 2."./ABNC001.JPG" ,or 3. Ignore and do not delete either file. (1/2/3)?:3 Ignoring... d41d8cd98f00b204e9800998ecf8427e ./ABNC001.JPG ERROR: Can't open md5sums.txt! ---Duplicates found--- Remove which file: 1."./Thumbs.db" , 2."./vincent05.jpg" ,or 3. Ignore and do not delete either file. (1/2/3)?:3 Ignoring... d41d8cd98f00b204e9800998ecf8427e ./vincent05.jpg ERROR: Can't open md5sums.txt! ---Duplicates found--- Remove which file: 1."./Thumbs.db" , 2."./tux_trek.gif" ,or 3. Ignore and do not delete either file. (1/2/3)?:
BTW this works (correctly) if i use "$data=`md5sum -b $file`;" instead...:
C:\WINDOWS\Profiles\madams\My Documents\My Pictures>md5sum -b Thumbs.d +b ABNC001.JPG vincent05.jpg tux_trek.gif 0b32237bb069cff23325ef2ea6c386ca *Thumbs.db 06b0c8cc903f49d131b27621389fb57d *ABNC001.JPG 032c0f9c5b5e9afe63936417037d8f4a *vincent05.jpg 8294e114b207d343000f74c72840a1ed *tux_trek.gif
note the code as is reports a bogus digest for Thumbs.db..
What went wrong?
_________________
madams@scc.net
(__) (\/) /-------\/ / | 666 || * ||----||

Comment on Why the same hex digest?
Select or Download Code
Re: Why the same hex digest?
by Albannach (Prior) on Mar 16, 2001 at 06:37 UTC
    Did you notice the error message? It was coming from this line: open(THISFILE,'< $file') or warn "ERROR: Can't open $outfile!\n";
    which means the input file is not being opened so you aren't MD5ing (nice verb) what you think you are. The single quotes stop the variable interpolation, try this: open(THISFILE,'<'.$file) or warn "ERROR: Can't open $file: $!\n";
    Note also that the warn should mention the correct file, not your output file. Even better, include $! to get more post-mortem info.

    --
    I'd like to be able to assign to an luser


      /me Do'oh!... Thanks Albannach, today is not my proofreading day i guess..dyslexia at work (i'm an accountant so that's BAD), and no speaka da perl at home... ;)

      I mean.. OF COURSE q() stops variable interp...so why do i now wear eggs?
      ++ for pointing out i'm a "luser" myself today heh,heh...

      UPDATE:
      this sorry story gets to be my entry to the end of:
      TIMTOWTDI -- so long as it's not my way

      _________________
      madams@scc.net
      (__) (\/) /-------\/ / | 666 || * ||----||
Re: Why the same hex digest?
by grinder (Bishop) on Mar 16, 2001 at 15:20 UTC

    An observation: you don't have to open the file and read it in bit by bit. You can pass the opened filehandle directly to the Digest::MD5 object.

    I posted some code a while ago that demonstrates the technique.


    g r i n d e r

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2014-09-22 04:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (178 votes), past polls