http://qs321.pair.com?node_id=11145439


in reply to Re^2: Filehandle in subroutine in use VRML.pm
in thread Filehandle in subroutine in use VRML.pm

I understand that you want to pass filehandles to functions with the added feature that if user specified ...

Alas it seems I did not understand exactly. In my code above I assume that you will open a file using open my $fh, ... and that you pass around that filehandle and not a literal string/bareword representing also a filehandle, which gets complicated, having to specify also package names. So, in the code I provided the part open $fh, '>', 'xxx'; is essential. The following works for me:

{ package main; my $fh = undef; VRML::printout('some lines1', $fh); open $fh, '>', 'xxx'; VRML::printout('some lines2', $fh); close $fh; } { package VRML; sub printout { my ($lines, $_fh) = @_; my $fh = $_fh ? $_fh : *STDOUT; print $fh $lines; } }

bw, bliako