How do you use opening files (open, three-arg open) with a short example?

In Perl, you can open files using the `open` function. The three-argument version of `open` is often preferred as it provides better safety against certain types of issues. Below is a simple example of how to use the three-arg `open` method.

keywords: Perl, file handling, open, three-arg open
description: This example demonstrates how to read from a file in Perl using the three-argument form of the `open` function.
#!/usr/bin/perl use strict; use warnings; # Open a file for reading my $filename = 'example.txt'; open(my $fh, '<', $filename) or die "Could not open file '$filename' $!"; # Read the file line by line while (my $line = <$fh>) { print $line; } # Close the filehandle close($fh);

keywords: Perl file handling open three-arg open