Recently, I was writing a Perl program that would, among other things, take some poorly-formatted phone numbers and pretty them up for display. We can dial internally using just the last 5 digits of the phone number. So, if I have a co-worker with the number "785-1234", I can just dial "5-1234" to reach him, while to reach "524-9876", I just dial "4-9876".

Because of this, many of the phone numbers in the input data were missing the leading 2 digits (not to mention the area code). We have a limited number of internal prefixes, so it was easy just to create a little hash to match up the missing digits with the 1-digit version abbreviations:

my %full_prefix = ( 78 => "5", # 785-xxxx 52 => "4", # 524-xxxx 78 => "2", # 782-xxxx );

You've already seen the problem, haven't you? I didn't. I fiddled with the cursed program for 20 minutes, trying to figure out why none of my tests were passing, before it finally occurred to me -- I had the keys and the values on the wrong sides! Doh! (*bang head on keyboard*) In splitting the numbers into the first two digits and the third digit, I forgot to swap them around.

So, to help me feel better about my obvious inability to handle even the most basic of Perl programming tasks, what was the most bone-headed programming error you ever made? I'm not talking about basic things that you didn't realize when you were just starting out. I'm thinking of things that you knew but somehow completely goofed on.

Please, make me feel better!

Wally Hartshorn

(Plug: Visit JavaJunkies, PerlMonks for Java)


In reply to (OT) What Was Your Most Bone-headed Programming Error? by Wally Hartshorn

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.