Skip to content

Commit 7557533

Browse files
committed
Some small improvements to io.pod
* do not advertise deprecated IO.slurp method * mention procedural form of &slurp * spaces instead of hard tabs
1 parent 738d615 commit 7557533

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/Language/io.pod

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ To read in the contents of a file one could open the file via the C<open>
1616
function with the C<:r> (read) file mode option and slurp in the contents:
1717
1818
my $fh = open "testfile", :r;
19-
my $contents = $fh.slurp;
19+
my $contents = $fh.slurp-rest;
2020
$fh.close;
2121
2222
where we explicitly close the file handle using the C<close> method on the
@@ -25,6 +25,8 @@ contents of a file. However, we can do the same much more easily and
2525
clearly like so:
2626
2727
my $contents = "testfile".IO.slurp;
28+
# or in procedural form:
29+
my $contents = slurp "testfile"
2830
2931
By adding the C<IO> role to the file name string, we are effectively able to
3032
refer to the string as the file object itself and thus slurp in its
@@ -73,21 +75,21 @@ exist. So, how do we know that the file even exists before reading it?
7375
This is what the C<e> method on an C<IO::Handle> object is for.
7476
7577
if "nonexistent_file".IO.e {
76-
say "file exists";
78+
say "file exists";
7779
}
7880
else {
79-
say "file doesn't exist";
81+
say "file doesn't exist";
8082
}
8183
8284
It is also possible to use the colon pair syntax to achieve the same thing:
8385
8486
if "path/to/file".IO ~~ :e {
85-
say 'file exists';
87+
say 'file exists';
8688
}
8789
8890
my $file = "path/to/file";
8991
if $file.IO ~~ :e {
90-
say 'file exists';
92+
say 'file exists';
9193
}
9294
9395
Similarly to the file existence check, one can also check to see if a path
@@ -113,7 +115,7 @@ the file test method C<f>:
113115
=head1 Getting a directory listing
114116
115117
To list the files and directories in the current directory, one merely needs
116-
to use the C<dir> function. This returns a list of C<IO::Path> objects one
118+
to use the C<dir> function. This returns a list of L<IO::Path> objects one
117119
can then write to, read from etc.
118120
119121
say dir; # "/path/to/testfile".IO "/path/to/lib".IO
@@ -147,3 +149,5 @@ TODO: http://doc.perl6.org/type/IO::Handle has close but no open
147149
=end comment
148150
149151
=end pod
152+
153+
# vim: expandtab

0 commit comments

Comments
 (0)