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

If you deparse for(;;){ you get:

perl -MO=Deparse -e"for(;;){ print 'hello' }" while (1) { print 'hello'; }

Whilst I agree while(1) { is clearer, for(;;){ isn't actually an error.


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?

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

    Ah, thanks. Didn't realize Perl already does that. Good catch!

    BREW /very/strong/coffee HTTP/1.1
    Host: goodmorning.example.com
    
    418 I'm a teapot
Re^3: Memory leak!
by ikegami (Patriarch) on Dec 13, 2011 at 02:52 UTC

    for(;;){ isn't actually an error.

    This is intentional. In both C and Perl, any combination of the three expressions can be omitted.

    • If the initialisation expression is missing, no initialisation is performed before entering the loop.
    • If the exit condition is missing, the loop doesn't exit.
    • If the counting expression is missing, no code is executed at the end of every pass.
      This is intentional. In both C and Perl, any combination of the three expressions can be omitted.

      I know.

      It means that instead of this:

      C:\test>perl -E"while(<>){ print }" hello hello goodbye goodbye ^Z

      We could write:

      C:\test>perl -E"for(;<>;){ print }" fred fred bill bill john john ^Z

      But few, if any, would.


      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?

        Sure, which is why noone does it. (1 down, 7 to go!)