Compact way of getting file checksum in Perl

前端 未结 3 488
清酒与你
清酒与你 2021-01-12 14:47

I am looking for ways to get file checksums in Perl but not by executing the system command cksum -- would like to do it in Perl itself because the script needs

3条回答
  •  清酒与你
    2021-01-12 15:15

    I couldn't make any of the above work for me in windows, I would always get an incorrect MD5. I got suspicious that it was being caused by differences in linebreak, but converting the file to DOS or to unix made no difference. The same code with the same file would give me the right answer on linux and the wrong one in windows. Reading the documentation, I finally found something that would work both in windows and linux:

    use Digest::MD5;
    open ($fh, 'new->addfile($fh)->hexdigest;
    

    I hope this helps other people having difficulty in windows, I find it so weird that I didn't find any mentions to problems on windows...

提交回复
热议问题