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)
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |