So I guess all that means that you avoid do { } blocks as well? After all, you can't put an explicit return in there either. Pity, you're missing out on a great tool to clarify and structure code. You'll find stuff like this all over my code:

my $timestamp = { my( $year, $month, $date ) = ( localtime )[ 5, 4, 3 ]; $year += 1900; $month++; join '-', $year, $month, $date; };

No leaked variables. Also trivial to refactor into a sub if I notice I need it more than once.

And if variable names are so important (yes, they are), what's that $hash doing there in your code?

In any case,

my @newLoop = map +{ PARTNAME => $_, SELECTED => $_ eq $row->{ title }, }, @$parts;

(No, it doesn't cost much extra memory. The base memory overhead of an anonymous hash is so large it easily overshadows an empty key. I'd build this structure inside-out by saying { SELECTED => 42, PARTS => [ 'foo', 'bar', 'baz', ... ] }, which takes a fraction of the memory and also makes updating the selected entry an atomic O(1) vs a two-step O(n) operation, but that's just me.)

Makeshifts last the longest.


In reply to Re^6: "advanced" Perl functions and maintainability by Aristotle
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.