in reply to Re: Is for(@$array_ref) construct optimized? YES!
in thread Is for(@$array_ref) construct optimized? YES!

Sorry, I just checked a situation and can not confirm your sayings. Here is my log:
D:\Work\PerlScripts\utl>perl -MO=Deparse -we "$x=[];for(@$x){}" $x = []; foreach $_ (@$x) { (); } -e syntax OK D:\Work\PerlScripts\utl>perl -MO=Deparse -we "$x=[];for(;;){}" Name "main::x" used only once: possible typo at -e line 1. $x = []; for (;;) { (); } -e syntax OK D:\Work\PerlScripts\utl>perl -MO=Deparse -we "$x=[];for($i=0;$i<=$#x;$ +i++){}" $x = []; for ($i = 0; $i <= $#x; ++$i) { (); } -e syntax OK
This is probably version-dependent (which perl version you use?) and with less probablilty $^O-dependent (what is $^O in your case?)

I think we'll find common denominator soon.

update: after I saw your update I understood more and now I think we found that commond denominator that I've just mentioned. Thanks.

Replies are listed 'Best First'.
(jeffa) 3Re: Is for(@$array_ref) construct optimized? YES!
by jeffa (Bishop) on Jun 16, 2002 at 20:22 UTC
    On Linux with Perl5.6.0:
    $ perl -MO=Deparse -we '$x=[];for($i=0;$i<=$#x;$i++){}'
    $x = [];
    $i = 0;
    while ($i <= $#x) {
        ();
    }
    continue {
        ++$i
    }
    -e syntax OK
    
    Screamer is right - but thanks for preaching anyway, not all of us are 'converted' just yet. ;)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      Aha! we see a difference between 5.6.0 and 5.6.1 with respect to this:
      D:\Perl56\bin>perl -MO=Deparse -we "$x=[];for($i=0;$i<=$#x;$i++){}" $x = []; $i = 0; while ($i <= $#x) { (); } continue { ++$i } -e syntax OK D:\>perl -MO=Deparse -we "$x=[];for($i=0;$i<=$#x;$i++){}" $x = []; for ($i = 0; $i <= $#x; ++$i) { (); } -e syntax OK
      Here I tried to compare 5.6.0 (I called it from 5.6.0 dir which is d:\perl56\bin in my computer) and 5.6.1 (it's in my $PATH)

      update I did update to call a snippet without compile errors; but explanation of results before and after update are same

        It's the B::Deparse version, not the Perl version that matters here.

        Makeshifts last the longest.