#!/usr/bin/perl
# File I/O !!!!!!! Chapter 8 ????????
use strict;
my $filename;
my $mode;
# three things you do to a file
# 1- open
# 2- access it (read or write)
# 3 - when you're all done : close
# example 1 writeing to a file
$filename="adam.txt";
$mode=">";
open OUTPUT1 ,$mode, $filename or die $!;
print OUTPUT1 "xxx hello there version 2\n";
print OUTPUT1 "yyy line 2 of the test\n";
print OUTPUT1 "bye bye\n";
close OUTPUT1;
# example 2 - reading a file one line at a time
my $line;
open INPUT1 ,')
{
chomp($line);
print "$line\n";
}
close INPUT1;
my @lines;
# slurping a file into an array
open INPUT1 ,"; # slurping a file
print @lines;
close INPUT1;
# appending to a file
open OUTPUT1, ">>adam.txt" or die $!;
print OUTPUT1 "appended line 1\n";
print OUTPUT1 "appended line 2\n";
close OUTPUT1;