in reply to return undef

I can't make sense of your question. If myfunction() returns a filehandle, then it is out of place in an expression like

print FILEHANDLE myfunction();
unless you want your output to look something like GLOB(0x1234567).

I think that what you want is something like

my $output_handle = myfunction(); if ( $output_handle ) { print $output_handle $whatever; } else { # deal with null-handle error }

the lowliest monk

Replies are listed 'Best First'.
Re^2: return undef
by dwijew (Initiate) on May 23, 2005 at 02:49 UTC
    when i use print FILEHANDLE myfunction(); the file that is being sent from my function gets copied into FILEHANDLE. thats what i want it to do. however if there is an error myfunction() returns undef. my question is how do i check if it is returning the filehandle or undef? in order to copy the file or display the error message?
      Ah, you've confused people with your terminology. You seem to mean that the function reads from a filehandle and returns the contents. Is this correct?

      If so, something like:

      my $filedata = myfunction(); if (defined $filedata) { print FILEHANDLE $filedata; } else { # handle error... }
      P.S. Showing some or all of myfunction() would really help us help you.

      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

        how would i return an open filehandle through a functon? aren't you supposed to send the contents of the file?
      There is a module for this: File::Slurp.


      holli, /regexed monk/