Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of jjore (6662)

Sunday July 05, 2009
12:48 PM

My first Perl 6 program

[ #39233 ]

I tried to write the program from http://use.perl.org/~jjore/journal/39223 in Perl 6 but failed. It's written but there an error being thrown from within the regexp engine that I'm going to have to debug. Anyway, this was instructive to me about what worked and what didn't.

I tried reading some of the S* documentation but found it hard going. I ended up just browsing around in the Rakudo and Parrot implementations and test suites to figure out how to write this.

I get the following errors depending on what files I give to this program. My next steps are to go to #perl6 or #parrot and see how I debug the regexp. (but plz, don't reply here w/ help. This blog post is not a bug report).

Null PMC access in get_string()
in regex PGE::Grammar::_block51 (tab-width.p6:9)
called from Main (tab-width.p6:31)

Malformed UTF-8 string
in method IO::slurp (src/gen_setting.pm:3279)
called from method IO::slurp (src/gen_setting.pm:596)
called from Main (tab-width.p6:14)

The code:

#!/home/josh/src/rakudo/perl6
for @*ARGS -> $ifn {
    next if $ifn ~~ m{'/.git'};
 
    # TODO: open( ..., :rw ) not implemented. Open a second file in :w
    # as a workaround.
 
    my $ifh = open $ifn, :r;
    # TODO: not implemented $fh.binmode;
    my $isrc = $ifh.slurp;
    $ifh.close;
 
    # TODO: s/// not implemented, try .subst as workaround
    # in Main (src/gen_setting.pm:3279)
    my $osrc = $isrc.subst(
        /   :i
            ^^
            $<variables> = (
                $<indent> = (\N*)
                    Local\ Variables\:\N*\n
                [ \N* \n ]*
            )
            $<end> = (
                \N* End\: \N* \n
            )
        /,
        {
            # TODO: "$<variables>$<indent>tab-width: 8\n$<end>";
            "{$0}{$0[0]}tab-width: 8\n{$1}"
        }
    );
 
    next if $osrc eq $isrc;
 
    # TODO: lack of builtin rename() means I have to
    # write to a temp file
    my $ofn = "$ifn.tmp";
    my $ofh = open( $ofn, :w );
    $ofh.print( $osrc );
    $ofh.close;
 
    # TODO: rename() builtin not implemented
    # rename $ofn, $ifn;
    run "mv $ofn $ifn";
}

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.