I'm currently learning how to read through large groups of text files to scan for key words for some research work I'm doing. I came across an example that I don't fully understand, mostly because my Perl knowledge is a little piecemeal and it's been tough trying to find a reference to what's going on.
The following piece of code is part of a program that takes a long text file (2000+ lines), scans it for some key words, and then logs the file name and some other details if the key words are present. Most things I've written have looped through the lines one at a time, because that's currently all I know how to do.
I found an example that reads the entirety of the file into a variable at once, but I don't know what's going on syntactically. The following code reads in the each file:
{
# this step removes the default end of line character (\n)
# so the the entire file can be read in at once.
local $/;
open (SLURP, "$direct"."$file") or die "can't open $file: $!";
$data = <SLURP>;
}
Then, I perform several simple regex matches using if statements.
What is the meaning of the local declaration in this case, and what does encapsulating the code segment do (if anything)? I get the comment that I am removing the end of line character, but I don't know how it's working.