Well, I was able to *find* the <INPUT> bug, but i was not able to *spot* it. So, what I will meditate on briefly is *finding* (slow) versus *spotting* (fast).
What I did: run the code with some test data, run it, look up $/ in perlvar, realize that's not the problem, read the code again, and finally realize the problem. Total time, maybe five minutes.

So, in this case, the perlish var threw me off. If the code had been written

#!/usr/bin/perl use strict; use warnings; use English; my $file = shift || die "No file, dummy!"; open FH, "<", $file or die "Could not open ($file) for reading: $!"; local $INPUT_RECORD_SEPARATOR = "\n.\n"; while (defined (my $record = <FH>)) { chomp $record; print $record; <STDIN>; }
I probably would have spotted it a lot faster. So maybe the "best practices" moral here would be to use English when doing this kind of magic thing. Even if you're a perlvar wiz, the guy maintaining your code may not be.

The second moral of the story is, with regards to finding versus spotting: if you've got a short little chunk of code like this and you know it's got a bug in it, read through every line. Read the first line. Think about it. Read the next line. Think about it. Until you've read every line. Seems like an obvious thing to do, but I am not in the habit of doing it. I am in the habit of write, try it out, check for bugs. I don't usually write then check for bugs.

But of the two morals, I think use English would probably save more time in the grand scheme of things. I may put this on my list of best practices now for everything other than $_. (I wonder whether damian conway mentioned the subject in his book?)


In reply to Re^3: Spot the Bug by tphyahoo
in thread Spot the Bug by Ovid

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.