in reply to Use of freed value

My guess it's a variation of the call($x++,$x++) side effect problem.

The @a has no refcount anymore after "emptying" it

The $r in the hint solved it.

Just a guess, no time to dig into the guts.

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

Replies are listed 'Best First'.
Re^2: Use of freed value
by ikegami (Patriarch) on Jun 26, 2019 at 17:05 UTC

    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.

      > 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.