Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??


Your code looks pretty nice, I'll have to try it out and check the E2PROM on some boards I have. I took a quick look at your code and have a couple suggestions (in no particular order):

  • You can simplify this statement: if ( ( $i + 1 ) / 16 == int( ( $i + 1 ) / 16 ) ) by using the modulo operator (%)--it does an integer division and gives you the remainder. Using it, you could write your statement as:
    if ( ($i+1)%16 == 0).
  • Generally you should declare your variables close to where you use them, in the innermost scope that makes sense. That limits the amount of code you need to review if you're looking for how the variable is used. This is causing you to double-comment certain things, kinda like:
    Line 38:
    my ($i2cBus, $i2cAddr);        # bus ID number & device address
    Line 54:
    #setup bus number, EEPROM address and max eeprom size in bytes $i2cBus = BB_I2C_PERI_1;

    If you declare the variable at the second point, you need only comment it once.

  • You're also commenting on things that need no comment. In the code below the comment we can see that it's setting the baud rate to 100kHz (due to the well-named value). In fact, with well-named variables, many comments are superfluous.
    # set baudrate to 100kHz (AT24C32 at 3.3v, max speed = 100kHz)) $objI2c->set_baudrate( $i2cBus, BB_I2C_CLOCK_100_KHZ );

    The comment about the part's limitations is something I'd put in the comment. If you decide later to use 50kHz because some flakey parts, you don't have to update your comment.

Keep in mind that these are just some trivial suggestions. If one of my colleagues gave me this code, I'd be perfectly happy with it going into production as it is (assuming that it does what it's supposed to). If you review some of my posts here, you'll notice that I frequently post code that could do with improvement as well.


When your only tool is a hammer, all problems look like your thumb.

In reply to Re: EEPROM on i2c Real Time Clock Modules by roboticus
in thread EEPROM on i2c Real Time Clock Modules by anita2R

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2021-10-23 19:10 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (88 votes). Check out past polls.