Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replace spurt with print when writing to an IO::Handle
  • Loading branch information
Paul Cochrane committed Feb 24, 2015
1 parent a646a74 commit ec25269
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
8 changes: 4 additions & 4 deletions lib/Language/io.pod
Expand Up @@ -37,10 +37,10 @@ the file for you.
To write data to a file, again we have the choice of the traditional method
of calling the C<open> function -- this time with the C<:w> (write) option
-- and spurting the data to the file:
-- and printing the data to the file:
my $fh = open "testfile", :w;
spurt $fh, "data and stuff\n";
$fh.print("data and stuff\n");
$fh.close;
We can simplify this by using C<spurt> to open the file in write mode,
Expand All @@ -57,7 +57,7 @@ To append to a file, one can specify the C<:a> option when opening the file
handle explicitly,
my $fh = open "testfile", :a;
spurt $fh "more data\n";
$fh.print("more data\n");
$fh.close;
or with the C<:append> option in the call to C<spurt>:
Expand Down Expand Up @@ -150,4 +150,4 @@ TODO: http://doc.perl6.org/type/IO::Handle has close but no open
=end pod

# vim: expandtab
# vim: expandtab shiftwidth=4 ft=perl6
9 changes: 2 additions & 7 deletions lib/Type/IO.pod
Expand Up @@ -291,8 +291,8 @@ directory.
Writes the indicated contents (2nd positional parameter, C<$what>) to the
location indicated by the first positional parameter, C<$where> (which can
either be a string, an C<IO::Path> object, or an already opened
C<IO::Handle> object).
either be a string or an C<IO::Path> object). To write to an C<IO::Handle>,
use the L<print> method.
If a file needs to be opened for writing, it will also be C<close>d. Returns
True on success, or the appropriate C<Failure> if something went wrong.
Expand Down Expand Up @@ -321,11 +321,6 @@ C<False>.
# write directly to a file
spurt "path/to/file", "default text, directly written";
# write to an IO::Handle
my $fh = "path/to/file", :w;
spurt $fh, "default text, written via IO::Handle";
$fh.close;
# write directly with a non-Unicode encoding
spurt "path/to/latin1_file", "latin1 text: äöüß", enc => "latin1";
Expand Down

0 comments on commit ec25269

Please sign in to comment.