Last night I was dreaming about the project I'm working on. so what? standard stuff. The project is all perl. No big deal, this is a perl site ...

But here's the really worrying bit: I woke up because part of my brain said "That code will never work. You need to ..." and then the debugging process woke up within me and my full consciousness returned pondering map{} and regexes and then I couldn't go back to sleep.

You know you're in for trouble when you start wondering whether

for (my $i=1; $i<=10000; $i++) { my $s = Sheep->new($i); $gate->through($s); }
would be more efficient written using an array like this:
my @herd; for (1..10000) { push @herd(Sheep->new($_)); } $gate->through(\@herd);
and then worrying whether you'd do even better to one line the whole thing
$gate->through(Sheep->new($_)) for (1..10000);
and then you wonder whether you couldn't fork() cunningly so that part of you is running Sheep->new($_) while another part is doing the gate->through($previous_sheep) bit. And then you wake up screaming because you still haven't figured out how to get windows to fork properly...

And we try again

$me =~ s!wide awake!fast asleep!g;
no hang on maybe I need to use the /e modifier.
$me =~ s!wide awake!asleep(fast)!ge;
no no no that'll never work I need quotes
$me =~ s!wide awake!asleep('fast')!ge;
ANd maybe I'm not wide awake so how about
$me =~ s!(wide )?awake!asleep('fast')!ge;
or better
$me =~ s!(?:wide\s+)?awake!asleep('fast')!ge;


Enter any 47-digit prime number to continue.

Replies are listed 'Best First'.
Re: Dreamig in Perl
by kodo (Hermit) on Dec 02, 2002 at 10:35 UTC
    Hi Dingus,

    I also had a time where I dreamed code. I remember even some situations where it was good code that solved a problem I had a day before, so I woke up next day and basically wrote down what I dreamed the night before. But of course most times there just was the way I could remember not the code lines themself.

    For some reason this stopped completly after a while, I didn't have any coding-dreams for quite a while now and I must say I'm quite happy with this.
    Of couse it's kinda funny and can really help in some situations but is it good to "think" while sleeping?
    I think it's not. Your body needs time to refresh, and your brain definitly also does. I found out that I'm much more refreshed and so can be more active and do better coding when I had a dreamless sleep.
    But we also have to seperate between normal "dreams" and dreams where your brain still thinks about everything. I also dreamed of chess-games when I was playing chess lots and I often dreamed of stock-charts when I did lots of trading.
    You always dream about such things when you can't leave them behind you once you left your desk...but I think you should try to really sleep and not only sleep with some parts of your body/mind...or you probably will get ill one day, getting serious problems to sleep etc.
    We already had such a discussion in the chatterbox I can remember and came to the conclusion that lots of coders don't sleep much and not very well. The deep-sleep-phase is kinda missing in lots of peoples sleep-time and that's what everyone should try to change.
    Good ways to do this I found out for myself are doing things like meditation (no not perl-meditation :) or going for walks in the nature for example. Find something to get your head clear (no drugs are bad!)...

    I hope I didn't miss the topic to much :)


      I doubt you ever had a dreamless night. You just don't remember the dreams. From what I've read about the subject the brain needs the dreams, to ease the strain, to filter and reprocess what happened, to forget, to remember ... You could have serious problems if you did NOT dream.

      I agree though that some walks and/or meditation (a nice lonely walk is a just meditation in motion :-) to clear ones head are good. Anything that'll help you fall asleep instead of rotating in the bed for hours rethinking your day/life is good. It's these halfdreams that drain ones strength. (Especially if you are a depressive fellow like me.)

      I'm having problems with this, especially during autumn+winter. I can't get up in the morning, I can't fall asleep in the night and all the time I feel like crawling into a cave and sleeping till the spring comes. I'll try if phototherapy helps.


        Well I think you're right, we usually do dream almost every night. I only had the feeling of those non-dream-nights when I did meditate lots over a weekend for example. This way all that stuff in my brain went by during meditation where the brain is a a very similar state like while sleeping but with your mind awake. It all passes by finally and you can come to the point where it all stops. This of course needs time of course but I had that experience and I guess in that state of mind you have dreamless nights.
        About walks I think it's an important point to NOT think about it all while walking, instead let it all pass by and just concentrate on the walk itself, then it can be like meditation yes.
        I also had similar problems to you for some time but it just got better and better...and I'm pretty sure it got better because I finally changed my way of live in lots of ways...
        You have to find the roots of that problem not fight the symptoms. In my case the problem simply was that I completly had lost the connection to nature and was living "online" more than I really lived. I also think food is an important point, and maybe the most important thing is to find back to calmness and not always hear/see something...find back to the root of all things.


      In college, I once dreamed I was in a program I was having problems with, stepping to each line and doing what it told me. I do not have any other vivid code dream memories since that one. Maybe the subsequent electroshock helped. 8-)

      A guy I worked with at my first job topped that. We had this godawful C program that was driven from a signal handler. Basically they were using signals and pipes as IPC; Process One would write a message and signal Evil Process Number Two to wake up and get its messages. Evil Process Number Two did eveything asynchronously from the signal handler. If you've ever lived the horrors of doing that in code that's not fully reentrant, you should be able to sympathize. This guy dreamed that he was being chased by the signals, which were striking at his feet like bolts of lightning. No lie. He left not long afterwards and went to law school.

      The interesting trivia associated with that Evil Signal Handling program is that a person whose name we all know wrote the original code. Many now look to him as a guru. I guess he had to learn somewhere. I will not incriminate him by giving his name.

      My big problem now is code daydreaming. It's a good way to pass the time when mowing the lawn, but when I zone out with the wife and kids present it's not so great. I just enjoy working problms over in my head like that, but it does tend to annoy those around me.

Re: Dreaming in Perl
by theorbtwo (Prior) on Dec 02, 2002 at 11:38 UTC

    To answer your question, the first and third will probably be about the same speed. The second will be significantly slower (lots of memory), and the fourth will be obscenly complicated. If it's much slower or about the same (or even faster!) depends mostly on how (explicitly) parallel your brain is.

    theorbtwo can't sleep either, but wasn't dreaming of code... as far as he remembers.

    Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

      I'm too lazy to benchmark, but since I know for(;;) is implemented in terms of while(){} continue{} and am fairly certain the list for the foreach is generated lazily in Perl5 (and thus juggling memory is not an issue), I'll hazard a guess that #3 should be the be the fastest of the lot.

      FWIW, I don't remember ever dreaming of code. Then again, I rarely ever remember anything but the worst of anxiety ridden dreams, so I may well have. Who knows?

      Makeshifts last the longest.

Re: Dreaming in Perl
by strat (Canon) on Dec 02, 2002 at 11:36 UTC


    that often happens to me when I've got a problem I thought about very much, but hadn't found a good solution. This very often happens with datastructures, but sometimes with algorithms too. This is one of the reasons why I try to sleep one night between planning and coding a bigger project... :-)

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8."

Re: Dreaming in Perl
by Callum (Chaplain) on Dec 02, 2002 at 14:05 UTC
    Though your not going to getting very restfull sleep if you're dreaming like this, it's worth noting that there's plenty of precident for serious scientific/technical work having foundation in dreams -- from Kekule's realisation of the ring structure of benzene molecules to Doc Brown's invention of time travel in Back to the Future :)
Re: Dreaming in Perl
by crouchingpenguin (Priest) on Dec 02, 2002 at 15:40 UTC

    I have had similar dreams, but I get into an endless loop of debugging where the solution presents new problems over and over again. I usually wake up to a stomach ache or some unpleasant physical symptom.

    I think the subconscious parallel between discomfort/pain to debugging the undebuggable is very amusing (looking back of course =] ).
Don't 'use Strict;' in your dreams
by flarg (Initiate) on Dec 02, 2002 at 18:44 UTC
    I've had quite a few anxiety-dreams in Perl. Usually I wake up in a sweat.

    Often I am able to go back to sleep if I simply remove the 'use strict;' line :)

    ... and a shot of whisky sometimes helps.

Re: Dreaming in Perl
by dws (Chancellor) on Dec 02, 2002 at 19:35 UTC
    I'M STUCK IN THIS HORRIBLE REGEX and it won't let me out! And I've been backtracking for days!

    Breath. Breath. Breath.

    Note to self: Gotta cut down on caffiene.

Re: Dreaming in Perl
by brianarn (Chaplain) on Dec 02, 2002 at 16:50 UTC
    You're not the only one. :) I'd post a lot about my dreams I've had in the past, but I already have.

    My Post on dreams

    I just had a project that was almost complete in Perl that I had to convert to be pure PL/SQL including creating stored procedures using an Oracle 9iAS server, so for the past few days I've been dreaming and thinking in Perl and PL/SQL mixed, which is freakin' scary. ;)

      My condolences on your PL/SQL dreams. Just how do you count sheep in SQL?


      Enter any 47-digit prime number to continue.
        SELECT COUNT(sheep) FROM flock;

        Sorry, couldn't resist... :-)

        -- JaWi

        "A chicken is an egg's way of producing more eggs."

Re: Dreaming in Perl
by Cody Pendant (Prior) on Dec 03, 2002 at 08:16 UTC
    I came up with some code in a dream that solved a problem once. I saw a little mental movie of an array being iterated through two by two, not one by one, and it looked like this
    foo,bar,baz,quux |___| foo,bar,baz,quux |___|
    and it turned out to be not a bad solution to the problem.
    ($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;