Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: CRC and Serial Port

by twerq (Deacon)
on Dec 05, 2001 at 01:47 UTC ( [id://129455]=note: print w/replies, xml ) Need Help??

in reply to CRC and Serial Port

about the checksum -- you obvously know more than I do about the other end that's sending you the data, but i've always done checksums on the whole record after zeroing the checksum, so you might end up having to pack it back up using the same unpack template...

...but for calculating the checksum itself, you might end up using unpack a third time

from perldoc -f unpack:
For example, the following computes the same number as the System V sum program: $checksum = do { local $/; # slurp! unpack("%32C*",<>) % 65535; };


Replies are listed 'Best First'.
Rea: CRC and Serial Port
by baku (Scribe) on Dec 06, 2001 at 02:48 UTC

    If you want to process data one block at a time, set $/ to your field length. That will save you from waiting to slurp the entire "file" before processing it.

      true, you can pass a value reference to $/ which translates into a record length, but as far as I know, there's no way to tell it to read 12 "lines", where a line can be variable length.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://129455]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-06-17 19:28 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.