First, I recommend you use the following to read the file:
my $buffer = do {
open(my $fh, '<', $filename)
or error_out("Error opening $filename: $!");
local $/;
<$fh>
};
Note the removal of the useless and potentially incorrect -s
. Note the use of a lexical variable for the file handle rather than a global one. Note the inclusion of the underlying error message in the error message.
The variable is a scalar. The value is a string.
for my $line (split(/^/m, $buffer)) { ... }
But why not just read it a line at a time.
open(my $fh, '<', $filename) or error_out("Error opening $filename: $!"); while (my $line = <$fh>) { ... }