Tony Bowden wrote:
That is what I'm saying. I'm aware that this is a controversial opinion in the Perl world. However, I think it's reasonable to know your audience and write for them. That's the good part of More Than One Way. The New York Times writes their articles for a certain reading level, and I do the same with my code.It sounds like you're saying that you should only use a subset of Perl as some programmers may not understand the other parts of it?
Note that different audiences have different levels. You can expect someone who opens up the code in a module on CPAN to be pretty fearless about advanced Perl ideas. On the other hand, the people in my current office are mostly novices so I try to take it easy on them when writing code for work. I will still use a Schwartzian Transform if I need one, but I'll put in a comment saying "this is a Schwartzian Transform, see such and such URL for an explanation." Same deal with things like hash-slices, and I try to avoid using $_ when it isn't necessary.
So would I, in that situation. It's not that map is so evil, but rather that I have often seen people overuse it (especially after a first-reading of "Effective Perl"), and write confusing code with it by jamming too much into the "map { some stuff } @list" form.Given: sub square { $_[0] ** 2 } my @nums = (1 .. 10); Which would say is more readable and maintainable? 1) my @squares; push @squares, square($_) for @nums; 2) my @squares = @nums; $_ = square($_) for @squares; 3) my @squares = map square($_), @nums; I'd go for (3) every time.
- Perrin