Thanks for your reply Keith. I am now seeing the same value generated
for three different .jpg files I am working with so I guess something
is still wrong with my code. Could you give me a final nudge in the
right direction? Here's the modified code:
#!/usr/local/bin/perl
use Digest::SHA1;
my $datafile = "c:\testerforanette.jpg";
my $file_is_binary = ! -T $datafile;
open ((MYNEWFILE, $datafile) || die ("Can't find file"));
if ($file_is_binary) {
binmode(MYNEWFILE);
print Digest::SHA1->new->addfile(*MYNEWFILE)->hexdigest, "\n";
close (MYNEWFILE);
}
I've noticed if I replace addfile(*MYNEWFILE) with addfile(MYNEWFILE).
I also get the same result. Thanks - Lee
ko <> wrote in message news:<>...
> Lee Hibberd wrote:
> > Hello all
> >
> > I have used sha1_file in php and want to know if there is an
> > equivalent in perl. i.e. I want to produce a sha1 value based on the
> > composition of the file and not the filename. I have used the perl
> > sha1 digest, but I'm unsure if this is working correctly. One reason
> > for my uncertainty is that the sha1 values produced by php sha1_file
> > differ. The second reason is I guess I would need to feed the
> > bit-stream through the sha1 in perl as if it were a line of text, and
> > I'm not sure that my code does that:
> >
> > my $fn="$file";
> > my $fh = new IO::File;
> > $fh->open($fn) or @row = $dbh->do( "
> > UPDATE All_Locations SET SHA1Date = Date(),SHA1Time =
> > Time(),ErrorCode=\'NoFile\' WHERE FileID=$row[0]
> > " );
> > $digest = new Digest::SHA1;
> > $digest->addfile($fh);
> > $fh->close;
> > $sha1var = $digest->hexdigest;
> > print $file.": ".$sha1var."\n";
> >
> > Any help would be greatly appreciated.
> >
> > Lee Hibberd
> > National Library of Scotland
>
> The documentation for addfile() states that the filehandle should be in
> binmode:
>
> use Digest::SHA1;
>
> open my $fh, shift or die $!;
> binmode($fh);
>
> print Digest::SHA1->new->addfile($fh)->hexdigest, "\n";
> close $fh;
>
> Digest::MD5 has an interface similar to Digest::SHA1 and example code
> you might want to look at.
>
> HTH - keith
|