in reply to Re: Memory leak!
in thread Memory leak!

Thanks for the advice on the closedir. I will add these in and see if it has an effect on the problem. Just for reference, is there much difference between infinitely looping using a

while(1) {}

loop rather than a

for (;;){}

loop?

Replies are listed 'Best First'.
Re^3: Memory leak!
by cavac (Prior) on Dec 12, 2011 at 19:48 UTC

    The first one makes it a bit clearer that you are intentionally looping an infinite number.

    I'm not sure about this, but the while loop may also be a tiny bit more efficient in this case.

    BREW /very/strong/coffee HTTP/1.1
    Host: goodmorning.example.com
    
    418 I'm a teapot

      cavac:

      You shouldn't speculate--just measure it with Devel::Benchmark!

      Roboticus ducks and runs while wondering if his machine can do more infinite loops per second than yours... ;^D

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

      How could doing more work (evaluating a constant) be more efficient?

      It's not less efficient either, though. while (CONSTANT) { ... } gets compiled as for (;;) { ... } or (); depending on whether the constant is true or false.

Re^3: Memory leak!
by ikegami (Patriarch) on Dec 13, 2011 at 02:19 UTC
    No, while (1) {} gets optimised to for (;;) {} (which I use and pronounced "for ever").
      No, while (1) {} gets optimised to for (;;) {} (which I use and pronounced "for ever").

      Er, no. for (;;) {} gets deobfuscated to:

      perl -MO=Deparse -e"for(;;){}" while (1) { (); } -e syntax OK

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        I know you know this, but for the benefit of other people reading: You can't always rely on Deparse as the canonical interpretation of the code as run, because it doesn't have all of the information the parser and optree constructor throw away. The best you can do is disable the optimizer and emit the optree (unless, of course, you care about what the optimizer has done).


        Improve your skills with Modern Perl: the free book.

        You said "no", but you didn't add anything to support that claim before changing the subject. Please elaborate.