The code you offer is certainly clearer to an individual who
has perhaps first started writing in Perl, coming from another
language, but I have to quibble with your statement that "it's
best."
Part of learning a new language is learning its idioms. The
implicit $_ is probably one of the most widely used idioms
in Perl, and appears in almost every well-written script. By
encouraging a new programmer to "pass by" that idiom, I think
you make it less likely that the person will learn its use.
I would say that it is actually "best to say" what the new
programmer will have to learn to program efficiently and to
read scripts by other programmers. After all, particularly in
this case, the implicit $_ is not a difficult concept. If the
new programmer doesn't learn it here, then learning grep and
map will only be that much more difficult.
As for the argument that one may introduce bugs if one starts
using things like grep, it only becomes that much more likely
that a programmer who is unfamiliar with the implicit $_
will
make such errors if you try to "hide" its use from him/her in
simpler structures.
-
HZ