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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.