Efficiency still is a reason to prefer map->assign over foreach(push). In the case of m// over index, its a case of allowing your needs to grow easily. When I use index I'm making a bet that I will only want to do exact string comparisons. That's frequently not the case over the long run so for that case, the decision often tilts toward m//.

Again, the code isn't written to be instructional to a novice. It is written to be usable by competent perl programmers. I don't much care if a C or VB programmer doesn't understand it right away. That is, assuming the code is in a place that I don't expect novice programmers to be. If I have the expectation that someone with lowered abilities to read perl is going to need to understand it, I will write in a way that maximizes readability. Often that must means using a few more intermediate variables but I know I've switched from a map->assign to foreach(push) just for that context. It is about what is situationally appropriate. I've no hard and fast rule and I don't expect anyone else to either. I do expect that programmers will let the current priorities guide how they work.

I should also note that while I do try to write in a style that prefers runtime efficiency over reabability by novices, I always try to keep it at a modest level and use as many layout hacks as necessary to make the structure apparent to me or someone of equal ability.


In reply to Re^10: "advanced" Perl functions and maintainability by diotalevi
in thread "advanced" Perl functions and maintainability by geektron

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.