Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

You need more coffee when...

by Anonymous Monk
on Apr 16, 2004 at 08:11 UTC ( [id://345676]=perlmeditation: print w/replies, xml ) Need Help??

Let's see. I just spent the last hour an a half to two hours debugging a snippet of code I wrote. You see, part of the task at hand was trying to locate the largest section of text within a document based on the location of a certain delimiter. I was effectively doing the following to do so:

my ($largest) = sort { length($b) <=> length($a) } $document =~ m!~\s*([^~]+?)\s*~!g;

The problem I finally discovered after playing with the regex delimiters for way over an hour? It is possible for the delimiters to be placed in such a way that certain sections will be skipped (and therefore the 'longest section' may not be discovered). Which as soon as I figured that out, my decaffeinated brain went "oh", maybe I should use split(). So, the simple fix that immediately fixed all problems I was having:

my ($largest) = sort { length($b) <=> length($a) } split(/~/, $document);

So, this is what happened to me on a day where caffeine failed to enter my bloodstream. My challenge to you? Reply to this node and share with everyone the most frustrating bug or issue you found in your own code that you just could not solve quickly, even though the answer was so obvious you are almost (or completely) embarrassed to admit. Whether it was caused by a caffeineless body or not -- me, I am sticking to the excuse that it is lack of coffee that made me clueless of a simple cure for my code!

Replies are listed 'Best First'.
Re: You need more coffee when...
by Abigail-II (Bishop) on Apr 16, 2004 at 10:42 UTC
    Something that happened 20 years ago, while in university. We had some programming assignment, in Pascal. Working in a pair (XP avant-la-lettre) we had this program with quite a bunch of procedures we just couldn't get to compile. Whatever we tried, it would always stop at the begin of the main program. We weren't able to fix it during our terminal time slot (16 terminals for about 200 people, each doing several courses that required terminal access - if we had 6 hours of terminal time a week, we considered it a lucky week). Still not having solved the problem, it was a topic of discussion during lunch the next day. One of our friends, a math student who wasn't very interested in programming, asked to see our program. We showed it to her, and she instantly spotted the problem - the name of the program didn't end with .p, which caused the compiler not to be happy with finding a main body in the file.

    <mode type = 'innocent'>That was the last mistake of such a kind I made.</mode>

    Abigail

Re: You need more coffee when...
by zentara (Archbishop) on Apr 16, 2004 at 14:12 UTC
    Often, coffee is not the "right medicine", a nap is. :-)

    Have you ever experienced "psychological blindness"?. 99% of vision is in the brain, not the eye. Have you ever looked so hard for something, that you did not see it, even though you were looking right at it? Sleep or nap is the cure.

    Alot of "avant-garde" companies now have "nap-rooms" where "bleary-eyed" workers can close their eyes for 20 minutes. It has been found to actually increase productivity and accuracy, far outweighing the lost time for the nap.

    Caffeine actually makes you more susceptible to "psychological blindness". A little caffeine may be good, too much may be bad.


    I'm not really a human, but I play one on earth. flash japh
      That would explain a lot about Apocalypse 12. :-)
Re: You need more coffee when...
by adrianh (Chancellor) on Apr 16, 2004 at 10:56 UTC

    Many years ago I spent a good six or seven hours with some Prolog code because I'd written my Variable as variable... sigh... happy days :-)

Re: You need more coffee when...
by Steve_p (Priest) on Apr 16, 2004 at 13:13 UTC

    A co-worker of mine and I stared at a chuck of code similar to the following for hours.

    for (i = 0; i < limit; i++); { do_something(i); }

    We could not figure out why the code after the for was only called once. We added printf statements. We ran it through debuggers (we tried several, assuming there was something wrong with them.

    Finally, blurry eyed, my co-worker said, "Why do I have a ";" right after the for?" He removed it, recompiled and everything worked fine. Yet another case of EBKAC.

Re: You need more coffee when...
by hardburn (Abbot) on Apr 16, 2004 at 13:48 UTC

    I was setting up a quick-and-dirty server to demo a few programs for the rest of the IT staff (like Subversion and RT). '/usr/local' had both 'apache' and 'apache2' directories holding the associated Apache version. Apache2 was doing Subversion and mod_perl2, and the orginal Apache was doing RT and mod_perl1. I had just shot off an e-mail to the IT staff to take a look at the RT installation. I then wanted to do some rebuilding of the Apache2/Subversion install, but in a combination of being too quick with Bash's tab compleation and being too liberal with my use of 'rm -rf', I had accidentally deleted the RT Apache instead. Naturally, this happend about a half-hour before I was supposed to leave for the day. I spent the next 30 minutes frantically rebuilding Apache/mod_perl and configuring RT back into place. Fotunately, I don't think anyone at that point had tried going into the system to take a look.

    Another embarrassing story (which didn't happen to me, but only because I had left the area a few minutes earlier) was at my LUG, where someone had brought in a SPARC to try to install GNU/Linux on. They had problems getting the boot manager to work, so someone came up with the great idea to dd the boot floppy directly to the hard drive. They found out that when you do that, your perfectly good 2 GB drive will suddenly think it's a 1.44 MB floppy.

    ----
    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

Re: You need more coffee when...
by zakzebrowski (Curate) on Apr 16, 2004 at 12:18 UTC
    For the life of me I couldn't (and still can't) figure out how it happened, but a special character must have been inserted into my perl file. I just couldn't see how the compiler was failing where it was, because it looked like fine to me. I asked someone else to look at it, and then he said that it should work as well. I don't know how I came to the conclusion that I should just use putty's copy and paste function, to copy the code, and re-paste it into the same document, but for some reason it worked! Ironically enough, btw, I just added to my home node my favourite type of coffee, which a local coffee shop has... Cheers.


    ----
    Zak - the office
Re: You need more coffee when...
by Aragorn (Curate) on Apr 16, 2004 at 09:33 UTC
    Ok, so you're proposing that we should tell our most painful secrets? To someone who posts his/hers anonymously?! Hm. No, don't think so... ;-)

    Arjen

      Ah, that was me ;) Must remember to login once in a while before I post.

Re: You need more coffee when...
by monsieur_champs (Curate) on Apr 16, 2004 at 17:30 UTC

    Fighting against time last week to deliver a new version of an old project dynamic website, and my perl Modules don't print their intended output. I fought against this every way you could think of during four hours non stop, until I disabled my browser's page cache, and everything goes fine.

    At this point I thank God for using CVS. This allowed me go back on every try (almost) and merge the important changes to de version I had at the beggining of my "Psicological Blindness".

Re: You need more coffee when...
by dbush (Deacon) on Apr 16, 2004 at 16:43 UTC

    This is an interesting coincidence, I was just about to post a meditation regarding a problem that I've just this minute figured out.

    use strict; use warnings; my %const; #Initialise params $const{pid} = 1; $const{pidwithzeros} = '0' x (10 - length $const{pid}) . $const{pi +d }, #Check params die "Invalid PID $const{pid}\n" if not $const{pid} =~ /^[0-9]+$/; #Various lines of code removed print $const{pidwithzeros}, "\n";

    I was getting an "uninitialized value in print" warning on the final line. The mistake is obviously that the comma at the end of line 8 should be a semi-colon but for the life of me I couldn't see it. To try and find out what was going on I changed the code to the following but this only deepened my confusion:

    use strict; use warnings; my %const; #Initialise params $const{pid} = 1; $const{pidwithzeros} = '0' x (10 - length $const{pid}) . $const{pi +d }, #Debug line print $const{pidwithzeros}, "\n"; #Check params die "Invalid PID $const{pid}\n" if not $const{pid} =~ /^[0-9]+$/; #Various lines of code removed print $const{pidwithzeros}, "\n";

    With the debug line in the code worked as expected. Without and the error would appear. Confusion reigned. Half an hour of thinking I was going bonkers later and as I was preparing a post to SoPW, I saw it.

    Hey hum.

    Regards,
    Dom.

      Not to completely miss the point, but you really should be using sprintf to do that:

      $const{pidwithzeros} = sprintf "%010d", $const{pid};
Re: You need more coffee when...
by bunnyman (Hermit) on Apr 16, 2004 at 17:23 UTC

    Once, years ago, while trying to compile a Pascal program, I wasted over an hour, trying to find out why the compiler was unable to find a subroutine that was obviously in my file -- right in front of my face!

    The problem turned out to be a Pascal style { comment } many screens away was missing it's closing brace, like this:

    { comment number one subroutine one { comment number two } subroutine two

    So the compiler thought my code was commented out and I thought it was code! That was the day I started using syntax colors in my text editors. When a big section of code is colored as grey, the cause is obvious!

      That's scarily similar to an experience I had in a CS2 course my freshman year. I didn't have the money for a commercial X-Windows server or the courage to install Linux on my desktop. So I was forced to work through a Putty window with no syntax highlighting, and a comment block killed the entire last half of my main program.

      Luckily a friend spotted it after a few hours, but I was seriously contemplating switching my major while trying to figure that out.

Re: You need more coffee when...
by bart (Canon) on Apr 16, 2004 at 16:19 UTC
    Your problem is that each match eats two "~" characters. So it'll skip every other section.

    Try this instead:

    $document =~ m!~\s*([^~]+?)\s*(?=~|$)!g;
Re: You need more coffee when...
by Anonymous Monk on Apr 17, 2004 at 19:09 UTC
    • skim samba manual
    • start experimenting
    • mount a random Win directory to *nix
    • play around with it
    • realize how cool samba is
    • get distracted
    • go off and do other things
    • come back and start to clean up
    • realize about 1 second too late that 'rm -R foo/' is, shall we say, very different from 'umount foo'
    • realize too late just how critical that 'random' Win directory was to many people
    • restore /foo from tape -- midnight the day before
    • apologies profusely for obliterating a day's work for whole team
    • creep away towards home
Re: You need more coffee when...
by Jenda (Abbot) on Apr 19, 2004 at 12:15 UTC

    A few years agon, while on univ, I was writing some test "program" in awk (or was it sed?). Of course it did not work and I was unable to find the reason for some 30 minutes ... until I noticed that I have a space at the end of one of the lines. And as soon as I deleted the space everything started to work fine. Oh my ...

    Though I don't think it was me who needed more coffee.

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://345676]
Approved by Corion
Front-paged by ysth
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (None)
    As of 2024-04-25 04:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found