Shlomi Fish <shlo...@shlomifish.org> writes: > Hi Lee, > > some comments on your code: > > On Wed, 12 Jun 2013 11:28:34 +0200 > lee <l...@yun.yagibdah.de> wrote: > >> David Christensen <dpchr...@holgerdanske.com> writes: >> >> > On 06/11/13 21:44, lee wrote: >> >> ... what I don't understand is what >> >> the most efficient way would be to create a sha-2 sum for a file. >> > >> > Have you considered Digest? >> > >> > http://perldoc.perl.org/Digest.html >> >> Yes, I've been looking at descriptions like that and I don't know perl >> well enough to understand them. I wanted to learn perl for ages and >> never got around to it. Now I'm finding it extremely useful, and I'm >> learning it the wrong way by not starting at the beginning ... >> >> I've come up with this for a test: >> >> >> #!/bin/perl > > Is your Perl at /bin? Shouldn't it be in /usr/bin?
It's in /bin: ,---- | [~/src/perl/test] which perl | /bin/perl | [~/src/perl/test] `---- >> use strict; >> use warnings; >> >> use Digest::SHA > > You're missing a ";" at the end. Ah, yes! >> >> our $fh; > > Why the our? I've been reading that you need to declare variables before using them when you use strict. A "my $fh;" would probably suffice. >> >> $ctx = Digest->new(SHA-256 => $arg); > > $ctx and $arg were not declared so «strict» will complain. I was expecting that; it just didn't get that far. Can I just omit the $arg? >> >> open $fh, "testfile"; > > 1. You shouldn't pre-declare $fh . So 'open my $fh, "testfile";' instead? > 2. You should use «use autodie;». ok :) >> $ctx->addfile( $fh); > > You can also add a filename using "->addfile ()" The description on [1] says it needs a file handle? >> >> print "hash: " . $ctx->b64digest . "\n"; >> > > This code won't compile. > > Perhaps learn Perl properly using some of the resources here: Yes, I should start at the beginning and/or take a class. I got so far that I can do what is needed, with the exception of creating the hashs. So maybe I'll have to use an external program like shasum until I figure out how to use the Digest ... [1]: http://perldoc.perl.org/Digest.html Meanwhile, I've found an example to learn from, and the following seems to work: #!/bin/perl use strict; use warnings; use autodie; use Digest::SHA; my $ctx = Digest::SHA->new(256); $ctx->addfile("testfile"); print $ctx->b64digest . "\n"; -- "Object-oriented programming languages aren't completely convinced that you should be allowed to do anything with functions." http://www.joelonsoftware.com/items/2006/08/01.html -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/