Inspired by the following perl one-liner perl -0777 -ne 'while(m/YOUR_REGEX_HERE/g){print "$&\n";}' YOUR_FILE_HERE, I am searching for the simplest way to read an entire file into a string (a procedure also known as “slurping”) in a complete perl file (not just a perl command), as I need to do simple operations using two files. I came around this: https://www.perl.com/article/21/2013/4/21/Read-an-entire-file-into-a-string/. (I am looking at Slurping files without modules.)
It suggests using
open my $fh, '<', 'text_document.txt' or die "Can't open file $!";
read $fh, my $file_content, -s $fh;
But how do I close the file after processing it? (1)
Also, how would that one-liner translate to a perl file, not just a perl command? (2)
Thank you!