Is there a more efficient way to get a checksum of all files in a directory?
sub print_dir { my $dir_name = shift; print "DIR: $dir_name\n"; opendir ( my $dir_h , "$dir_name") or die "Unable to open dir :$dir +_name: $!\n"; while ( my $path = readdir($dir_h) ) { next if ($path eq "." or $path eq ".."); my $full_path = "$dir_name/$path"; if ( -l $full_path) { my $linkref = readlink($full_path); print " LINK: $full_path ==> $linkref\n" if $opt_debug; push(@bom_data, { Type => "symlink", Name => "$full_path", LinkR +ef => "$linkref" }); } elsif ( -d $full_path ) { push(@bom_data, { Type => "dir", Name => "$full_path" }); print_dir ( $full_path ); } else { my $ctx = Digest::Adler32::XS->new(); my $file_h = IO::File->new($full_path, "r"); die "? Error: Unable to open $full_path for read: $!" if (not de +fined($file_h)); binmode($file_h) || "? Error: Unable to set binmode on $file_h: +$!\n"; $ctx->addfile($file_h); $file_h->close; my $cksum = $ctx->hexdigest; print " FILE: $full_path ==> $cksum\n" if $opt_debug; push(@bom_data, { Type => "file", Name => "$full_path", Checksum + => "$cksum"}); } } close $dir_h; }
Thanks for any suggestions.

In reply to Re^3: Calculating the crc checksum of a file using perl? by jimsearle
in thread Calculating the crc checksum of a file using perl? by AGhoulDoingPerl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.