Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Hash only portion of a file

by Kenosis (Priest)
on Jan 19, 2014 at 03:05 UTC ( [id://1071158]=note: print w/replies, xml ) Need Help??


in reply to Hash only portion of a file

Another option is to local $/ = \1_048_576; to read the first 1MB:

use strict; use warnings; use Digest::MD5 qw/md5_hex/; my $md5_hex_1m = file_md5_hex_1m('File.txt'); print $md5_hex_1m; sub file_md5_hex_1m { my ( $file, $contents ) = @_; local $/ = \1_048_576; open my $fh, '<', $file or die $!; return Digest::MD5->new()->add($contents)->hexdigest if defined( $contents = <$fh> ); }

Replies are listed 'Best First'.
Re^2: Hash only portion of a file
by Anonymous Monk on Jan 19, 2014 at 06:46 UTC
    Can you please explain this? I was under the impression $/ only matches a character or number of characters, how does it match 1 million counts of characters?

      That's the way it works. Please see  $/ in perlvar. (AKA  $INPUT_RECORD_SEPARATOR and  $RS. See also
          perldoc -v "$/"
      from the (update: Windoze) command line — use single-quotes in *nix (update: but see choroba's reply below).)

        As $/ is not a valid identifier name in shell (at least bash), you can use double quotes, too, as well as no quotes at all.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      "Setting $/ to a reference to an integer, scalar containing an integer, or scalar that's convertible to an integer will attempt to read records instead of lines, with the maximum record size being the referenced integer number of characters"

      This is really cool. I also didn't know it, because i didn't read the whole manpage ;-(

      Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1071158]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-03-28 11:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found