in reply to Re^3: shift on empty array in list context broken
in thread shift on empty array in list context broken

well not really short and concise...

undef is/was IIRC meant to free memory.

though I can't reproduce any difference between an emptied and destroyed array.

list context different:

DB<49> undef @x DB<50> x [ shift @x, splice @x,0,1 ] 0 ARRAY(0x34a5270) 0 undef DB<51> @x=() DB<52> x [ shift @x, splice @x,0,1 ] 0 ARRAY(0x34a6c48) 0 undef DB<53>

scalar context same

DB<54> undef @x DB<55> x [ ($a=shift @x), ($b=splice @x,0,1) ] 0 ARRAY(0x34a6960) 0 undef 1 undef DB<56> @x=() DB<57> x [ ($a=shift @x), ($b=splice @x,0,1) ] 0 ARRAY(0x34a6f18) 0 undef 1 undef

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^5: shift on empty array in list context broken
by Don Coyote (Hermit) on Jul 16, 2019 at 14:25 UTC

    I am viewing the docs, x [maxdepth] expr\n\tEvaluates its expression in list context .... Would this affect the interpretation of the contexts?

      > Would this affect the interpretation of the contexts?

      No, the context of x is not propagated.

      the [...,...] is imposing list context

      DB<50> x [ shift @x, splice @x,0,1 ] 0 ARRAY(0x34a5270) 0 undef

      to enforce scalar context I used a scalar assignment

      DB<60> x [ ($a=shift @x), ($b=splice @x,0,1) ]

      if you have doubts enter a call to a sub which returns the context depending on wantarray

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

        > if you have doubts enter a call to a sub which returns the context depending on wantarray

        DB<35> sub context { local $\="\n";print wantarray ? "list" : define +d wantarray ? "scalar" : "void";() } DB<36> x [ ($a= context), (context) ] scalar list 0 ARRAY(0x3466930) 0 undef DB<37>

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