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

> 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

Replies are listed 'Best First'.
Re^8: shift on empty array in list context broken (show context)
by Don Coyote (Hermit) on Jul 18, 2019 at 14:22 UTC

    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.

Re^8: shift on empty array in list context broken (show context)
by Don Coyote (Hermit) on Jul 20, 2019 at 16:43 UTC

    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

      Sorry, but what are you trying to show here?

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

        hello LanX

        Apparantley I am trying to show how little I understand contexts, module building and the debugger. :laugh

        I think what I am trying to get at is in principle what the OP is about. A reason for equivalent built-ins providing alternate implementations.

        Framing the issue of assignment in differing contexts by different built-ins within a wider context, so to speak.

        Amalgamating my existing Perl knowledge along with recently learnt knowledge, to do so. With varying results in the offspring.

        As an example, if this is an issue with shift, does pop return a different result?

        Also I am looking at how the comma operator is affecting the return list. I am not clear on which built-in is returning undef or empty in list context