Hi Lee, thanks for replying to the list and for not top posting.
See below for my comments. On Wed, 12 Jun 2013 17:50:57 +0200 lee <l...@yun.yagibdah.de> wrote: > 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] > `---- > Ah, is this part of the /usrmove ? http://fedoraproject.org/wiki/Features/UsrMove > >> 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. You can do the declaration during the open. > > >> > >> $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? I think so. > > > >> > >> open $fh, "testfile"; > > > > 1. You shouldn't pre-declare $fh . > > So 'open my $fh, "testfile";' instead? Yes, exactly. > > > 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? Well, https://metacpan.org/module/MSHELOR/Digest-SHA-5.84/lib/Digest/SHA.pm is OK with giving a file. > > >> > >> 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 ... There are some reasons for why not to use external programs: http://perl-begin.org/tutorials/bad-elements/#calling-the-shell-too-much > > > [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"; Yes, this is OK. Regards, Shlomi Fish > > -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Buffy Factoids - http://www.shlomifish.org/humour/bits/facts/Buffy/ Sometimes you don’t need to be familiar with a better alternative to know that something sucks. Take Microsoft Word for example. — Shlomi Fish’s friend. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/