226:0
  ;   ˆl—Ðz¾”Êe¶…6 ¸ÛWyLZ7ÿÂ„b?a–Ü4ý()¨‰P@Šû�Á<¦-ÿÁ ;w    =encoding utf8

=head1 NAME

perlopentut - simple recipes for opening files and pipes in Perl

=head1 DESCRIPTION

Whenever you do I/O on a file in Perl, you do so through what in Perl is
called a B<filehandle>.  A filehandle is an internal name for an external
file.  It is the job of the C<open> function to make the association
between the internal name and the external name, and it is the job
of the C<close> function to break that association.

For your convenience, Perl sets up a few special filehandles that are
already open when you run.  These include C<STDIN>, C<STDOUT>, C<STDERR>,
and C<ARGV>.  Since those are pre-opened, you can use them right away
without having to go to the trouble of opening them yourself:

    print STDERR "This is a debugging message.\n";

    print STDOUT "Please enter something: ";
    $response = <STDIN> // die "how come no input?";
    print STDOUT "Thank you!\n";

    while (<ARGV>) { ... }

As you see from those examples, C<STDOUT> and C<STDERR> are output
handles, and C<STDIN> and C<ARGV> are input handles.  They are
in all capital letters because they are reserved to Perl, much
like the C<@ARGV> array and the C<%ENV> hash are.  Their external
associations were set up by your shell.

You will need to open every other filehandle on your own. Although there
are many variants, the most common way to call Perl's open() function
is with three arguments and one return value:

C<    I<OK> = open(I<HANDLE>, I<MODE>, I<PATHNAME>)>

Where:

=over

=item I<OK>

will be some defined value if the open succeeds, but
C<undef> if it fails;

=item I<HANDLE>

should be an undefined scalar variable to be filled in by the
C<open> function if it succeeds;

=item I<MODE>

is the access mode and the encoding format to open the file with;

=item I<PATHNAME>

is the external name of the file you want opened.

=back

Most of the complexity of the C<open> function lies in the many
possible values that the I<MODE> parameter can take on.

One last thing before we show you how to open files: opening
files does not (usually) automatically lock them in Perl.  See
L<perlfaq5> for how to lock.

=head1 Opening Text Files

=head2 Opening Text Files for Reading

If you want to read from a text file, first open it in
read-only mode like this:

    my $filename = "/some/path/to/a/textfile/goes/here";
    my $encoding = ":encoding(UTF-8)";
    my $handle   = undef;     # this will be filled in on success

    open($handle, "< $encoding", $filename)
        || die "$0: can't open $filename for reading: $!";

As with the shell, in Perl the C<< "<" >> is used to open the file in
read-only mode.  If it succeeds, Perl allocates a brand new filehandle for
you and fills in your previously undefined C<$handle> argument with a
reference to that handle.

Now you may use functions like C<readline>, C<read>, C<getc>, and
C<sysread> on that handle.  Probably the most common input function
is the one that looks like an operator:

    $line = readline($handle);
    $line = <$handle>;          # same thing

Because the C<readline> function returns C<undef> at end of file or
upon error, you will sometimes see it used this way:

    $line = <$handle>;
    if (defined $line) {
        # do something with $line
    }
    else {
        # $line is not valid, so skip it
    }

You can also just quickly C<die> on an undefined value this way:

    $line = <$handle> // die "no input found";

However, if hitting EOF is an expected and normal event, you do not want to
exit simply because you have run out of input.  Instead, you probably just want
to exit an input loop.  You can then test to see if an actual error has caused
the loop to terminate, and act accordingly:

    while (<$handle>) {
        # do something with data in $_
    }
    if ($!) {
        die "unexpected error while reading from $filename: $!";
    }

B<A Note on Encodings>: Having to specify the text encoding every time
might seem a bit of a bother.  To set up a default encoding for C<open> so
that 