Skip to content

Commit 7fd6d67

Browse files
committed
add documentation about file test operators
1 parent e973f74 commit 7fd6d67

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

lib/IO.pod

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,75 @@ To include only the files with .pl extension write
3434
3535
dir(test => /.pl$/)
3636
37+
=head2 prompt
38+
39+
Prints out a string to the standard output and waits
40+
for the user to type in something and finish with an ENTER.
41+
The types string without the trailing newline will be returned.
42+
43+
my $name = prompt("Hi, what's your name?");
44+
45+
=head2 File Test operators
46+
47+
-e
48+
-f Do not exist in Perl 6 see :e, :f
49+
50+
-M Does not exist in Perl 6. See C<modified>
51+
-A Does not exist in Perl 6. See C<accessed>
52+
-C Does not exist in Perl 6. See C<changed>
53+
54+
:e Exists
55+
:d Is a directory
56+
:f Is a file
57+
:l Is symbolic link
58+
:r Readable
59+
:w Writable
60+
:x Executable
61+
:s size
62+
:z Is size zero?
63+
64+
Usage:
65+
66+
If you have a string - a path to something in the filestem:
67+
68+
if "path/to/file".IO ~~ :e {
69+
say 'file exists';
70+
}
71+
72+
my $file = "path/to/file";
73+
if $file.IO ~~ :e {
74+
say 'file exists';
75+
}
76+
77+
If you already have an IO object in $file, either by creating yourself,
78+
or be getting it from another subroutine, such as C<dir>,
79+
you can write this:
80+
81+
my $file = "path/to/file".IO;
82+
if $file ~~ :e {
83+
say 'file exists';
84+
}
85+
86+
There are also 3 methods for fetching the 3 timestamps of a file (indode),
87+
on Operating Systems where these are available:
88+
89+
=head2 modified
90+
91+
timestamp when the file was last modified.
92+
93+
"path/to/file".IO.modified()
94+
95+
=head2 accessed
96+
97+
timestamp when the file was lasy accessed.
98+
99+
"path/to/file".IO.accessed()
100+
101+
=head2 changed
102+
103+
timestamp when the inode was last changed.
104+
105+
"path/to/file".IO.changed()
106+
37107
=end pod
38108

0 commit comments

Comments
 (0)