Both are possible; it all depends what you want to do. Here's a function that returns an open read handle:
sub rh {
my $filename = shift;
open my $in, '<', $filename
or die "Couldn't open $filename for reading: $!\n";
return $in;
}
my $in = rh( 'somefile.txt' );
print while <$in>;
If your myfunction returns the contents of a file, then see ysth's reply.
|