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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Finally can someone comment on the indentation? Does it make sense they way I did it? It looks less messy but no clue if I got the philosophy behind it.

The philosophy is not tricky. Indentation is supposed to make the code easier to read by making it very obvious to the observer where each block of code and/or each statement starts and ends. This is particularly important when you end up with multi-line statements or a number of blocks which close at the same time.

With that in mind, indenting by 1 space for each level will earn you very few friends. Even worse you have been inconsistent. Compare the indenting of the while loop which reads the file versus the following for loop which starts the processing - the former is less indented than the latter which is wrong and therefore misleading to anyone reading the code.

Use 2 spaces for each indent at the bare minimum. The most widely used within perl modules appears to be 4 (among the code I've seen).

Alternatively you can use tabs. This has the advantage that you can use one character (a tab) per indent and then anyone else viewing the code can simply set the tab width to whatever they prefer. The choice of tabs vs spaces is a highly personal one, however, so be aware that you won't please everyone (see No Hard Tabs in Code). Do not use tabs for alignment.

Finally, until you understand what you are doing with indentation (and even then too), consider perltidy


In reply to Re: how to get average of matrices' elements? by hippo
in thread how to get average of matrices' elements? by fasoli

Title:
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 How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (1)
As of 2024-04-25 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found