[perl #132885] .next-handle seems to change handles but doesn't

[email protected] ("brian d foy")
Newsgroups perl.perl6.compiler
Message-ID <[email protected]>
# New Ticket Created by  "brian d foy" 
# Please include the string:  [perl #132885]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=132885 >


#!/Users/brian/bin/perl6s/perl6-latest

I'm playing with .next-handle from IO::CatHandle. I'm
trying to create a situation where I can read just the first five
lines from each command line argument:

    quietly {
        my $limit = 5;
        for lines() {
            state $lines = 1;
            FIRST { $*ARGFILES.on-switch = { put "NEW FILE"; $lines = 1 } }
            if $lines > $limit {
                $*ARGFILES.next-handle;
                next;
                }
            put "{$*ARGFILES.path}:{$lines++} $_";
            }
        }

Here's a test file:

    First
    Second
    Third
    Fourth
    Fifth
    Six
    Seventh

With one or more command-line arguments I get this odd behavior (and
lots of warnings that I suppressed):

    test.txt:1 First
    test.txt:2 Second
    test.txt:3 Third
    test.txt:4 Fourth
    test.txt:5 Fifth
    NEW FILE
    :1 Seventh
    read bytes requires an object with REPR MVMOSHandle (got VMNull
with REPR Null)
      in block <unit> at lines-method.p6 line 5

It does "switch" after five lines, but then it keeps reading from the
same handle while losing a line. Then there's a strange error at the
end that kills the whole thing.

I expected that it would close the current handle, open a new one, and
continue. If it gets to the end, it would simply not provide any more
lines() and things would end normally.

The docs for .next-handle lets you keep changing it as long as you
like no matter how many

-----

This is Rakudo Star version 2018.01 built on MoarVM version 2018.01
implementing Perl 6.c.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.