Mostly Harmless Docs/Files and IO

# Get a list of everything in the cwd (including dirs and dotfiles),
# but excluding '.' and '..'
my @files-here = dir;

# Reading files.
my @lines = open('foo.txt').lines;
my $whole-enchilada = slurp 'foo.txt';

# Read a file line-by-line.
my $f-in = open 'foo.txt';
for  $f-in.lines -> $line {
    say "line is: \"$line\"";
}
$f-in.close;

# Process a file character-by-character.
my $f-in = open 'foo.txt';
while $f-in.getc -> $i {
    say "character is: \"$i\"";
}
$f-in.close;

# Write to a file.
given open('foo.txt', :w) {
    .say('line one');
    .say('line two');
    .close;
}

# File tests
'foo'.IO ~~ :e   # check if it exists
'foo'.IO ~~ :d   # check if it's a directory
'foo'.IO ~~ :f   # check if it's a file

# Interactive I/O
loop {
    my $foo = prompt "say something: ";
    say "You said: $foo.";
    last if $foo ~~ 'quit';
}

# Shell out to some external command.
my $p = qx/ps -ef | grep fire/;
my $p = qx[ps -ef | grep fire];  # same

# Write to stderr.
note "You might like to know this ...";
# This one gives you a line number as well.
warn "You really ought to know that ...";

# Write to stderr, then exit.
die "Khan!!!!!";

Main | Next: The MAIN Sub