in reply to Re: Why doesn't perl optimize this?
in thread Why doesn't perl optimize this?

Agreed!

Maybe clearer: [@a] creates the ref to a copy (and copying is expensive) while \@a is the ref to the original array (no costs!).

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^3: Why doesn't perl optimize this?
by nbtrap (Sexton) on Jun 04, 2013 at 02:09 UTC
    I know the difference. My question was not about the difference, it was about why the difference is not optimized away in cases like the one I cited.
      You seem to believe in magical powers of static code analysis in a dynamic language.

      plz tell me

      sub func { my ($code,@a) = @_; my $b = [@a]; eval $code; return $b; }

      How is the compiler supposed to know that '@a' can be destroyed w/o knowing what happens in '$code' at runtime?

      Cheers Rolf

      ( addicted to the Perl Programming Language)

        I agree that the compiler can't know in the case you cite. But what about the case I cited?