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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.