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.

I concur. And I'll submit that $_ is actually quite intuitive -- it's just other programming languages that are unintuitive, unfamiliar and (arguably) unnatural in this regard.

For me, $_ is simply the current topic that's being talked about. Like in natural languages, sometimes you leave it out entirely, since it's clear from the context what's being meant; sometimes you merely say "this" or "it" (which is how I read $_). Perl doesn't go quite as far as natural languages where you can have several of these at once, but on the other hand, unlike natural languages, Perl cannot afford to be ambiguous ("Bill met Bob. They talked, and he gave him back the book" is fine; the same thing in Perl wouldn't be).

Still, having one "topic" is better than having none, as most programming languages do. Natural languages are intuitive, after all, and we're all familiar with them.


In reply to Re^2: foreach loop and creating files with "$_" by AppleFritter
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.