stevieb has asked for the wisdom of the Perl Monks concerning the following question:

So, I've spent an hour or two every night this week reading through the perl6 intro, and several of the various official perl6 docs, but I've run into an issue. I don't know if this is my problem, or a problem with the docs.

From the open() documentation, there is the following code example (spurt() simply prints something to the file):

my $fh = open("test", :w); spurt $fh, "stuff\n";

But when I test it (code is verbatim, the line num in the error is the spurt() line):

my $wfh = open("in.txt", :w); spurt $wfh, "a\n"; $wfh.close;

... it results in:

Type check failed in binding $path; expected Cool but got IO::Handle ( +IO::Handle.new(:path(...) in block <unit> at nl.pl6 line 2

Can someone explain where I'm going wrong? If it's relevant, I just installed the most recent p6 bits yesterday afternoon.

Replies are listed 'Best First'.
Re: Perl6: unexpected exception when printing to a writable file handle
by stevieb (Canon) on May 28, 2016 at 14:54 UTC

    Another case of Rubber Duck Debugging... (and not reading enough docs).

    From the spurt() docs:

    To write to an IO::Handle, use the print method.

    So I have to do this:

    my $wfh = open("in.txt", :w); $wfh.print("a\n"); $wfh.close;

    ...or, skip opening the file entirely, and pass the filename to spurt() directly:

    spurt "in.txt", "a\n";

    So I'll re-review the docs, as the example in my OP appears to be incorrect (I'll submit a patch if this turns out to be the case after more testing).

      Yes, the docs are incorrect. A patch fixing them just went in: https://github.com/perl6/doc/pull/555/files

        As a side question, is there an official location to discuss making potential changes to the docs?

        I'm speaking about many of the docs, but as an example, in Str type doc, I think it would be useful to have a very short brief of what each entry does. eg:

        1. Methods: 2. routine chomp - removes trailing newlines

        If this is wanted, I'd start the process and send PRs. I feel it would help future readers, and if I start this process, it'll allow me to learn very quickly as I'd have to read every single entry (while testing it), and that'd solidify things much faster than reviewing the docs periodically (and missing/not knowing about methods and functions that I don't even know exist).

        Thanks for the clarification, Zoffix! I'm glad that I was reading and understanding things properly.