Help for this page

Select Code to Download


  1. or download this
        # Get rid of all line endings, regardless of which flavor they are
        (my $line = shift) =~ s/[\r\n]//g;
    
  2. or download this
        # does this look like a S1, S2, or S3 record? These are the only o
    +nes that
        # carry an actual data payload. Other record types do not, so just
    + ignore
    ...
        # Make sure the COUNT field makes sense. It should represent the s
    +um of
        # address, data, and checksum fields, in bytes
        return unless hex($count) == (length($address) + length($data) + l
    +ength($cs)) / 2;
    
  3. or download this
        my $compCs = hex($count);
        foreach my $nibble ($address =~ m/../g, $data =~ m/../g) {
            $compCs += hex($nibble);
        }
    
  4. or download this
        my $compCs = hex($count);
        $compCs += hex($_) foreach($address =~ m/../g, $data =~ m/../g);
    
  5. or download this
        my $compCs = reduce { $a + $b }
                     map    { hex $_  }
                     ($count, $address =~ m/../g, $data =~ m/../g);
    
  6. or download this
        my $status = $compCs == hex($cs);
    
  7. or download this
    use List::Util;
    
    ...
    
        return ($status, $address, $data);
    }
    
  8. or download this
        # ...
    
        # if the checksum actually matches, then call it a good S-record
        return ($compCs == hex($cs), $address, $data);