Opening file for reading



While working over most of the operating systems today, no program can
access a file directly. This is in order to allow the Operating System
to apply user rights.

Before you can read from a file you have to ask the Operating System to "open"
it for you. When opening a file you provide a variable that will become your
handle to the opened file. It is called a filehandle.


examples/files-perl/open_file.pl
#!/usr/bin/perl
use strict;
use warnings;

my $filename = "input.txt";
open(my $fh, "<", $filename);

close $fh;

Open and read from text files