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

I think you are confusing the meaning of copying filehandles with that of copying the contents from one file to another.

I am guessing that it is the latter that you really want. I assume that myfunction returns either an open read handle or undef. In this case, you can do something like

my $in = myfunction(); if ( $in ) { print FILEHANDLE while <$in>; } else { # handle null-handle error; }

the lowliest monk

Replies are listed 'Best First'.
Re^4: return undef
by dwijew (Initiate) on May 23, 2005 at 03:00 UTC
    how would i return an open filehandle through a functon? aren't you supposed to send the contents of the file?

      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