in reply to EEPROM on i2c Real Time Clock Modules

A problem with writeI2cEeprom.pl

45 getopt('at:'); 46 our ( $opt_a, $opt_t ); ... 75 } elsif ( $opt_a > $eeMax ) { ... 126 if ( $opt_a + $dataLen > $eeMax ) { 127 $dataLen = $dataLen - ( $opt_a + $dataLen - $eeMax ); 128 } 129 # 130 # convert start address if hex value used 131 if ( substr( $opt_a, 0, 2 ) == "0x" ) { 132 $opt_a = hex($opt_a); 133 }

If $opt_a contains, for example '0xAB', then lines 75, 126 and 127 will not work correctly.

Lines 130 to 133 should be moved before $opt_a is used in a mathematical context.

Some problems with readI2cEeprom.pl

36 getopt('alo:'); 37 # 38 our ( $opt_a, $opt_l, $opt_o, $opt_h, $opt_v ); ... 53 if ( $opt_a > $eeMax ) { ... 102 # convert start address if hex value used 103 if ( substr( $opt_a, 0, 2 ) == "0x" ) { 104 $opt_a = hex($opt_a); 105 }

Same problem as with the other file. Lines 102 to 105 should be moved before $opt_a is used in a mathematical context.

79 if ( !$opt_o == undef ) {

Incorrect use of undef. That should be if ( !defined $opt_o ) {

Naked blocks are fun! -- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re^2: EEPROM on i2c Real Time Clock Modules
by hippo (Archbishop) on Aug 13, 2023 at 10:24 UTC
    That should be if ( !defined $opt_o ) {

    You have negated the logic. It should actually be the even simpler if (defined $opt_o) {


    🦛