in reply to Re^3: "advanced" Perl functions and maintainability
in thread "advanced" Perl functions and maintainability
Note how remarkably the block looks like the block of the foreach loop. Except that it doesn't have the push on the last line (if variables are so important, why use an out-of-scope variable for its side-effect if you don't have to?), just a result. IMO, clear. The map-block does only what it needs to do: get a value, calculate the result. It doesn't get globbered with array constructing code.my $newLoop = [ map { my $hash = {PARTNAME => $_}; $hash->{SELECTED} = 1 if $_ eq $row->{title}; $hash; } @$parts ];
I base by preference on the knowledge that variable names are perhaps the single most powerful form of documentation programmers have available to them, and one construct encourages you to give a name to list iterator while the other doesn't.Ah, that explains why your alternative to map starts with:
Nice name for the list iterator!for (@$parts)
Furthermore, map blocks are indeed meant to be short because each one is evaluated for its result.Does that mean that subroutines that have a return value have short blocks, and any subroutine that has a long block isn't supposed to have a return value? Or does this piece of logic only apply to map blocks?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: "advanced" Perl functions and maintainability
by William G. Davis (Friar) on Dec 13, 2004 at 14:58 UTC | |
by Aristotle (Chancellor) on Dec 20, 2004 at 04:36 UTC |