in reply to Re: Treating the file contents of a text file as a string
in thread Treating the file contents of a text file as a string
It would be better to minimise the change to the global $/ (record separator) variable, as this may cause action at a distance in some other part of the code (or a module). This is done by reducing the scope to the shortest possible block.
You are also repeating yourself. This is not good.
my $string = slurp($file1) . slurp($file2); sub slurp { my $file = shift; open $fh, <, $file or do { warn "Failed to open $file for input: $!\n"; return ''; } local $/ = undef; return <$fh>; # $fh goes out of scope, file closed automatically }
• another intruder with the mooring in the heart of the Perl
|
|---|