in reply to Re^3: return undef
in thread return undef

how would i return an open filehandle through a functon? aren't you supposed to send the contents of the file?

Replies are listed 'Best First'.
Re^5: return undef
by tlm (Prior) on May 23, 2005 at 03:04 UTC

    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.

    the lowliest monk