In such situations, I find it best to use named parameters to explicitely choose which is being passed:
sub doFile { my (%param) = @_; if ( defined($param{'filename'}) ) { warn( "We were passed a filename.\n" ); } elsif ( defined($param{'filehandle'}) ) { warn( "We were passed a filehandle.\n" ); } else { die( "We did not get a filename or filehandle.\n" ); } } # this for a filename: doFile( filename => 'foobar.qux' ); # or this for a filehandle: doFile( filehandle => \*DATA ); # or filehandle => $fh
In reply to Re: Function that accepts either a file name or a handle
by Anonymous Monk
in thread Function that accepts either a file name or a handle
by eyepopslikeamosquito
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |