in reply to Digest::CRC giving unexpected result

Okay, you can ignore this! Despite spending two days on it so far I've just found out that I shouldn't be converting the data to hex first. I'd thought that this was necessary but I'm getting the correct checksum with plain text. Sorry to have troubled you.
  • Comment on Re: Digest::CRC giving unexpected result

Replies are listed 'Best First'.
Re^2: Digest::CRC giving unexpected result
by AnomalousMonk (Archbishop) on Nov 30, 2016 at 14:28 UTC

    Thanks for the heads-up on your solution.

    BTW and FWIW, unpack with the  H template specifier is more efficient than  s///e in converting character strings to Intel hex. The only thing unpack doesn't offer (AFAIK) is control over the case of converted hex digits (lc by default), but this can easily be had with a supplemental uc call:

    c:\@Work\Perl>perl -wMstrict -le "my $dataToCheck = 'The Rain in Spain Falls'; ;; (my $h1 = $dataToCheck) =~ s/(.)/sprintf('%X',ord($1))/eg; my $h2 = uc unpack 'H*', $dataToCheck; ;; print qq{'$dataToCheck' -> '$h1'}; print qq{'$dataToCheck' -> '$h2'}; ;; die 'not the same' unless $h1 eq $h2; " 'The Rain in Spain Falls' -> '546865205261696E20696E20537061696E204661 +6C6C73' 'The Rain in Spain Falls' -> '546865205261696E20696E20537061696E204661 +6C6C73'
    See also pack (for all the template specifiers) and perlpacktut.


    Give a man a fish:  <%-{-{-{-<