open a file in Perl
Open for reading:
open my $fh, '<:encoding(utf8)', $filename or die "Could not open '$filename' $!"
Open for writing:
open my $fh, '>:encoding(utf8)', $filename or die "Could not open '$filename' $!"
Open to append:
open my $fh, '>>:encoding(utf8)', $filename or die "Could not open '$filename' $!"
- Open and read from file
- Always use 3-argument open
- Never the old way
Published on 2021-04-07
If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub.
Comment on this post