Perl find size of file with Checksum ( unpack)

I need to find and some some file sizes from a perl script there is some issues with this compare using just the files size "$x = -s $y;

I need to use Checksum to do an unpack to get what I need:

For example I can get the size I need from command line such as:

cat file.text | perl -e '$/=undef;print q{Checksum is }, (unpack(q{%32c*},<>) % 65535), qq{\n}'

Open in new window


But don't seem to be putting this in the script to work correctly.

How can I do this from a script if I have a file in the script such as:

$sum = '/tmp/file1.txt';

Thanks,
bt707Asked:
Who is Participating?
 
FishMongerCommented:
Digest::MD5 should do what you need, but you could also look at:
Digest - Modules that calculate message digests
Digest::SHA - Perl extension for SHA-1/224/256/384/512

That are both core modules so they should already be installed on your server, assuming you have a recent perl version.

Digest was first released with perl v5.7.3

Digest::SHA was first released with perl v5.9.3
0
 
bt707Author Commented:
From perldoc -f unpack:

        For example, the following computes the same number as the
        System V sum program:

            $checksum = do {
                local $/;  # slurp!
                unpack("%32W*",<>) % 65535;
            };


I could use this but can't seem to put in what I want is to check?

The size of:
$sum = '/tmp/file1.txt';

Do I need to open and read $sum the put it in the check somehow?

Thanks,
0
 
FishMongerCommented:
Why not use one of the many available digest modules.

Here are a few commonly used digest modules used to calculate a checksum.
Digest::CRC - Generic CRC functions
Digest::MD5 - Perl interface to the MD5 Algorithm
Digest::Adler32::XS - Generate Adler32 digests efficiently
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
bt707Author Commented:
FishMonger,

I need a module that is already on the server, it takes forever to get a change request approved just to update a new module to the server.

I checked those, so do see one that is on the server, let me see what I need to do with that one and see if it gives what I need.

perl -MDigest::MD5  -e 'print $Digest::MD5::VERSION'
2.36


Thanks,
0
 
bt707Author Commented:
I have:

This is perl, v5.8.4 built for sun4-solaris-64int

so should have what you pointed out, just got tied up with other issues, but it looks like the info you gave should do just what I need.

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.