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

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

Replies are listed 'Best First'.
Re^6: shift on empty array in list context broken
by LanX (Saint) on Jul 16, 2019 at 17:21 UTC
    > 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

        Right, now I've gone a bit more towards a TAP approach, but I'm having difficulties getting my plans to run. So far I've got:

        C:\Users\Theseus\perlmonks\sopw\11102936>dmake test C:\"Dwimperl\perl\bin\perl.exe" "-MExtUtils::Command::MM" "-MTest::Har +ness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib\lib +', 'blib\arch')" t/*.t t/00-load.t ....... # Testing SoPW_11102936 0.01, Perl 5.014002, C:\Dw +imperl\perl\bin\perl.exe t/00-load.t ....... ok t/01-works.t ...... Not an ARRAY reference at C:\Users\Theseus\perlmon +ks\sopw\11102936\blib\lib/SoPW_11102936.pm line 78. t/01-works.t ...... 1/9 # Looks like you planned 9 tests but ran 1. # Looks like your test exited with 255 just after 1. t/01-works.t ...... Dubious, test returned 255 (wstat 65280, 0xff00) Failed 8/9 subtests t/manifest.t ...... skipped: Author tests not required for installatio +n t/pod-coverage.t .. skipped: Author tests not required for installatio +n t/pod.t ........... skipped: Author tests not required for installatio +n Test Summary Report ------------------- t/01-works.t (Wstat: 65280 Tests: 1 Failed: 0) Non-zero exit status: 255 Parse errors: Bad plan. You planned 9 tests but ran 1. Files=5, Tests=2, 1 wallclock secs ( 0.05 usr + 0.05 sys = 0.09 CPU +) Result: FAIL Failed 1/5 test programs. 0/2 subtests failed. dmake: Error code 255, while making 'test_dynamic'

        The Module and Test as is:

        fyi report bugs here in the thread is fine. I've not uploaded to cpan.

        see Update

        Ok I've had another go. This time within the debugger and the output is leaning more towards concise. However, I am now unsure whether I have something that could relate to the issue or if it's because am still noobing DB.

        Apart from getting contexts out of kilter, there are a couple of issues. Firstly,( moved to new SoPW Should high traceDepth trace into debugger code? )

        Secondly, I get a 'panic' warning, about attempting to copy a freed scalar. So I'm in panic mode and posting this now, along with the trace I attempted. Its probably nothing right?

        Update Ok scratch that, I added use strict; Also, moved the 'Firstly' out to a new SoPW.

        After attempting to do as you suggested, and reading plenty (read not nearly enough) of documentation, I have a little more appreciation for the debugger and how it can be used. If not actually managing to get any closer to the OP.

        As for using wantarray to view the contexts, for a moment there I thought there was a void built-in.

        But I see now that they are word-strings being returned to represent contexts.

        documentation visited