Why do you say "our" and "we"? I'm clearly not part of the intended audience. Here are some coding tips that may help you no longer be part of the intended audience either.

First suggested change, start declaring all of your variables with my. That allows you to start using strict.pm.

Second suggested change, never call &do_something without parentheses unless you really want the @_ aliasing. If you don't know what I mean, then trust me that you didn't want to do that.

Third, don't write C-style for loops without specific reason. One of the most common bugs in C is off-by-one errors in a loop. (Yes, even for very experienced people. Track yourself.) Using C-style loops is going to cause you to have the same errors in Perl.

Fourth, avoid action at a distance. Trying to remember whether you've played with $[ will cause even more off-by-one mistakes. Learn how Perl likes to work, and stick with that. You'll have fewer errors. (And will be less likely to break any modules that you want to load.)

Fifth, learn the difference between the range and flip-flop operators. Yes, list vs scalar context can be confusing. But in Perl it is also very important.

Sixth, always say what you want directly. If you want to loop over 1..10 you can do that directly with either looping style. Just do it.

And last, but not least, if you want to loop over an array, at least 95% of the time it is best to just do it directly and forget about what the index is:

for my $thing (@stuff) { do_something($thing); }
(Note that I don't use the & on the function call. That is intentional, but it is a minor style decision of mine allowing me to be more consistent across languages. It isn't an important preference.)

In reply to Re: The Zeroeth Principle by tilly
in thread The Zeroeth Principle by Velaki

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.