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


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 {
            put "{$*ARGFILES.path}:{$lines++} $_";

Here's a test file:


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

Reply via email to