sub ReadTheEntireFile
{
my $F = defined $_[0] ? $_[0] : '';
$F =~ tr`<>*?\"\|\x00-\x1F``d; # Remove illegal characters.
length($F) or return ''; # Missing file name?
-e $F and -f $F or return ''; # Make sure file exists.
my $SIZE = -s $F; # Get file size.
$SIZE or return ''; # Return zero bytes.
my $BUF = ''; # Read buffer
local *FILE;
sysopen(FILE, $F, 0) or return ''; # Open file for read only.
my $L = sysread(FILE, $BUF, $SIZE); # Read the entire file
close FILE;
return $BUF;
}
Again, you don't need both file tests to know if a file exists.
$L contains the amount of data returned from the file. You should compare that value to $SIZE to verify that the entire file has been returned.
Naked blocks are fun!
-- Randal L. Schwartz, Perl hacker