?
Solved

Perl find size of file with Checksum ( unpack)

Posted on 2012-08-17
6
Medium Priority
?
674 Views
Last Modified: 2012-08-17
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,
0
Comment
Question by:bt707
  • 3
  • 3
6 Comments
 

Author Comment

by:bt707
ID: 38306447
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
 
LVL 28

Expert Comment

by:FishMonger
ID: 38306545
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
 
LVL 28

Expert Comment

by:FishMonger
ID: 38306557
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:bt707
ID: 38306585
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
 
LVL 28

Accepted Solution

by:
FishMonger earned 2000 total points
ID: 38306642
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
 

Author Closing Comment

by:bt707
ID: 38306655
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question