My first Perl 6 program

jjore on 2009-07-05T17:48:12

I tried to write the program from http://use.perl.org/user/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 ^^ $ = ( $ = (\N*) Local\ Variables\:\N*\n [ \N* \n ]* ) $ = ( \N* End\: \N* \n ) /, { # TODO: "$$tab-width: 8\n$"; "{$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"; }