Perl6::Overview::File - File and Filesystem operations Structure
FH = open FILENAME, MODE # FH is the returned filehandle # FILENAME is, well the name of the file # MODE can be :r :w :a :rw # if MODE left out it defaults to :r my $fh = open "filename", :r orelse die "Could not open file $!"; my $row = =$fh; # reading a line my @rows = =$fh; # reading all the lines my $content = slurp "filename"; # slurp the content of a file into a scalar variable close $fh;
my $dh = opendir "dirname" orelse die "Could not open directory $!"; my @files = readdir($dh); my @files = $dh.readdir; for $dh.readdir -> $entry { # read them one-by-one say $entry; } closedir($dh); $dh.closedir; rewinddir($dh); # start from the beginning $dh.rewinddir;
"thing" ~~ :e # true if thing exists in the filesystem "thing" ~~ :d # true on directories "thing" ~~ :f # true on files "thing" ~~ :r # true on readable files/directories "thing" ~~ :w # true on writable files/directories "thing" ~~ :x # true on executable files/directories "file" ~~ :z # true if size is 0 "file" ~~ :s # returns file size in bytes mkdir "dirname" rmdir "dirname" chdir "dirname" unlink chmod chown
To install Perl6::Doc, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perl6::Doc
CPAN shell
perl -MCPAN -e shell install Perl6::Doc
For more information on module installation, please visit the detailed CPAN module installation guide.