in reply to Checksum Help

Give this a try:
$ cat ./crc32.pl #!/usr/bin/env perl use strict; use warnings; use String::CRC32; die "Usage: crc32.pl file\n" unless @ARGV; for my $file (@ARGV) { open my $fh, '<', $file or die "can not open file $file: $!"; my $crc = crc32($fh); close $fh; printf "%08x %s (%08x)\n", $crc, $file, (0xffff_ffff - $crc); } $ ls *.txt data.txt file.txt golf.txt $ ./crc32.pl *.txt d13bcbe6 data.txt (2ec43419) 0b8c331a file.txt (f473cce5) 5f20086b golf.txt (a0dff794) $

Replies are listed 'Best First'.
Re^2: Checksum Help
by TeamViterbi (Novice) on Jul 07, 2009 at 21:54 UTC
    Hey toolic, Thanks for helping me out with this. I've got a few questions about this code though, mainly cause I dont fully understand perl yet, bare with me if you dont mind. I read that "#!/usr/bin/env perl" should always go first in the code. What is $cat? I also dont understand what is going on with the .txt near the bottom. What are the numbers in () and why are they there? and can this program work with .bin files? Thanks so much for helping me out. I really appreciate it.
      What is $cat?
      The '$' is the command line prompt conventionally used for the Unix Bourne shell. cat is a unix command which shows the contents of a file. There is a space between '$' and 'cat'. When I saw #!/usr/bin/perl in your code, I assumed you were on a unix-like operating system. What OS are you on?

      I used cat to show you the contents of the Perl program file that I adapted from your code. I named the file 'crc32.pl'. I then used the ls unix command to show you the listing of files in my directory which have a 'txt' extension. The output of ls shows 3 files.

      Finally, I ran the Perl program, and you can see 3 lines of output, 1 for each plain text input file.

      What are the numbers in () and why are they there?
      They are the results of the difference between 0xffffffff and the CRC values, expressed in hexadecimal notation.
      and can this program work with .bin files?
      I don't know what you mean by .bin file. Does the String::CRC32 documentation mention what file types are supported by the module?