Perlfunc: pfile() 2010-09-16 01:40pm
PHP has a handy function named file() that will read the contents of a file into a variable. I wrote a quick Perl version of the same function.
sub pfile {
my $file = shift();
my $ret = '';
if (!-r $file) { return ''; } # Make sure the file is readable
# Loop through each line and build the $ret string
open(INPUT,$file);
while (my $line = <INPUT>) { $ret .= $line; }
close INPUT;
return $ret;
}




