hello |@perl6-users,

I'm trying to implement the MARC::MIR spec in Perl6 so i need to read 
ISO2709 files (which is an old but still frequently used file format to store
book records for libraries).

In ISO2709, record separator (RS) is \x1d so the Perl5 implementation does:

our $RS = "\x1d";

sub iso2709_records_of (_) {
    my $fh;
    if ( ref $_[0] ) { $fh = shift }
    else { open $fh, shift or die $! }
    sub {
        local $/ = $RS;
        <$fh> // ();

as i saw in IO.lines (rakudo/core/IO.pm:129)

    my Str $x = nqp::p6box_s(nqp::readlinefh($!PIO));

then in the readlinefh implementation (MoarVM/src/io/fileops.c:235)

    if (ch == 10 || ch == 13) break;

the RS is hardcoded. I finally end up to gathering characters of the

sub iso2709_records_of ( $input ) {
    gather {
        my $record='';
        while not $input.eof {
            my $c = $input.getc;
            if $c eq "\x1d" {
                    take $record;
            else { $record~= $c }
        take $record;

But i guess it's inefficient and i have to admit i expected a shorter code.

Come on, Perl6 people! did i miss something that takes carre of separators? 
it would be nice to have something like:

@posix-users = "/etc/passwd".IO.records( :rs("\n"), :fs(":") )

to gather something like

     ( < root x    0    0 root /root      /bin/bash > \
     , < mc   x 1000 1000 marc /home/marc /bin/zsh  > )

Speaking about ISO2709 format, it would be:

@records = "book.mrc".IO.records( :rs("\x1d"), :fs("\x1e"), :ss("\x1f"))

but i seen nothing in the doc or the code.


Marc Chantreux (eiro on github and freenode)
"Don't believe everything you read on the Internet"
    -- Abraham Lincoln

Reply via email to