Hello james28909,
Your use of $_ to generate the filenames “temp1”, “temp2”, ... “temp5” looks fine to me. There is, in general, nothing wrong with using $_. On the contrary, $_ is one of Perl’s strengths, because it facilitates the writing of concise, elegant code.
In the article you reference, apotheon recommends this rule of thumb for $_: If you have to use it explicitly, use something else instead. So far as I can see (I’ve only skimmed the article), the only justification given for this opinion is that:
a lot of people find $_ ugly and even obfuscatory.
Possibly true, but then they are people who don’t know and use Perl! Perl is, by design, an atypical language, so its idioms and byways are often unintuitive at first, but unfamiliar should never be mistaken for ugly. As apotheon notes, people who find Perlish idioms ugly sometimes avoid Perl itself for that reason. IMHO that is not necessarily a bad thing.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: foreach loop and creating files with "$_"
by Athanasius
in thread foreach loop and creating files with "$_"
by james28909
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |