in reply to Re: Use of freed value
in thread Use of freed value

call($x++, $x++) works in an unsurprising manner.

$ perl -e'$x=3; CORE::say for $x++, $x++' 3 4

I think you're referring to the oddities of call(++$x, ++$x).

$ perl -e'$x=3; CORE::say for ++$x, ++$x' 5 5

or

$ perl -e'$x=3; CORE::say for $x, $x++' 4 3

These occur because $x and ++$x (and --$x) add the scalar $x itself to the stack rather than a copy. $x++ (and $x--) necessarily add a copy of the original value.

Well, the problem is related to the scalars themselves being on the stack, so the explanations are indeed related. But that's just the precondition for the problem, not the answer itself.

Replies are listed 'Best First'.
Re^3: Use of freed value
by LanX (Saint) on Jun 26, 2019 at 17:25 UTC
    > I think you're referring to the oddities of

    Yes

    > so the explanations are indeed related. But that's just the precondition for the problem, not the answer itself.

    Well I tend to avoid such side effects because of this experience.

    I don't necessarily need to know why I suffer after crossing the red line.

    Update

    And it's a pretty good guess inside the 15 min window you left us before answering it yourself. ;)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      Well I tend to avoid such side effects because of this experience.

      hum? We use the side effects of putting the actual scalars on the stack all the time (e.g. $x = 3;). I presume you mean you avoid using writing to the scalar twice in the same statement, and avoid writing to the same scalar twice in the same statement.

      The thing is, @a, @a=() doesn't do that, at least not any more than splice(@a) or shift(@a) do, and I'm pretty sure you don't avoid those.

        > I'm pretty sure you don't avoid those.

        I rarely chain statements having side effects with the coma operator.

        Only exception are one liners.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice