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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |