matt brings up a good point back on the main thread, that $. will count correctly even when the special <> magic handle moves from file to file. Doing that yourself means testing eof in your loop too, and complicating things.

Update:Well, it seems that $. doesn't reset on each file normally. You need to add a close ARGV if eof;statement inside the loop anyway!

But, your argument is that the magic <> is obsure so you shouldn't use that either—with so much magic and subtlety, “to the average programmer, especially one not intimately familar with Perl, is that they don't make any sense.”

But it does something so useful that would be a lot of code to do yourself! The program would be harder to figure out, and possibly buggy, if you did it yourself. And if all that code was put into a module and you got it down to a single function call, well, that's just what <> does in the first place.

So, given the sentiment that obscure things can make it difficult for maintaniance, where do you draw the line? Answer: how easy is it to look up? If the obscure thing is some idiom spread over a few lines, and you don't know the name of it, how do you look it up anywhere? But a particular function call or special variable is easy to look up in the manual under that name. In the former case, always use a comment that could be as simple as naming the construct, e.g. "sort using the or-cache maneuver".

—John


In reply to Re: Re^4: Determining what line a filehandle is on by John M. Dlugosz
in thread Determining what line a filehandle is on by Anonymous Monk

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.