in reply to Re: Re: for ( ; ; ) vs for ( .. )
in thread for ( ; ; ) vs for ( .. )

B::Deparse is your friend here.
$ perl -MO=Deparse -e 'for ($x = 0; $x < 10; $x++) {}' $x = 0; while ($x < 10) { (); } continue { ++$x }
So the answer would be yes. As to whether there's extra scope overhead, well, we'll leave that as an exercise for the reader.

Replies are listed 'Best First'.
Re: Re: Re: Re: for ( ; ; ) vs for ( .. )
by lestrrat (Deacon) on May 23, 2002 at 22:09 UTC

    which version of perl? I can't seem to reproduce it... Mine is 5.6.1 on a solaris

    me@myhost> perl -MO=Deparse -e 'for( my $x = 0; $x < 10; $x++ ) { pr +int "foo\n" }' for (my $x = 0; $x < 10; ++$x) { print "foo\n"; } -e syntax OK me@myhost>
      5.6.0 on OS X. Same result on 5.005_03. Presumably either Deparse or the peephole optimizer were thumped in 5.6.1 giving the different result.
Re: Re: Re: Re: for ( ; ; ) vs for ( .. )
by demerphq (Chancellor) on May 24, 2002 at 08:55 UTC

    B::Deparse is your friend here.

    Ah. Well. Coming from you I'll take your word for it. But frankly I tend not to trust B::Deparse too much. :-)

    D:\Development>perl -MO=Deparse -e "for ($x = 0; $x < 10; $x++) {}" for ($x = 0; $x < 10; ++$x) { (); } -e syntax OK D:\Development>perl -MO=Deparse,-x3 -e "for ($x = 0; $x < 10; $x++) { +}" $x = 0; while ($x < 10) { (); } continue { ++$x } -e syntax OK

    This is on 5.6.1 AS631. Btw from the documentation for the -x switch


      Expand conventional syntax constructions into equivalent ones that expose their internal operation. LEVEL should be a digit, with higher values meaning more expansion. As with -q, this actually involves turning off special cases in B::Deparse's normal operations.


    Which suggests to me that im right. (But which is also why I asked a Guru like yourself. I was hoping for a definitive answer that did not depend on Deparse.)

    Nevertheless, thanks.

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.
      Older versions of deparse are accurate, as far as it goes. The problems in the node you referenced aren't Deparse's fault--it's not currently possible to turn an optree back into the source it came from. There's a not insignificant amount of stuff that's thrown away during the compile or peephole optimization phase, which makes things a bit tough.

      Hey, at least I didn't recommend you rebuild perl with -DDEBUGGING and dig through the output of perl -Dt... :)

        rebuild perl with -DDEBUGGING

        Remarkably, the only reason im able to write this post (im at work) is because I decided to compile Perl with -DDEBGGING (but to add a debug switch to see whats happening with parsing and creating arguments in win32.c, yes i know -Dp does it, the yydebug was getting on my nerves...) and in a fit of stupidity deleted the win32/include directory :(

        So maybe once I've finished Ill take a look...

        Incidentally (re)learning c from perls source code is proving to be an interesting exercise. ;-)

        Yves / DeMerphq
        ---
        Writing a good benchmark isnt as easy as it might look.